We are excited to announce that the ASP.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

# how can I seperate the integerpart and decimal part [Answered] RSS

## 4 replies

Last post May 30, 2019 01:23 PM by mgebhard

• polachan

Member

414 Points

1339 Posts

### how can I seperate the integerpart and decimal part

May 30, 2019 10:40 AM|polachan|LINK

I have the following values in MondayHrs and TuesdayHrs . How can I find the TotalHrsinMins

decimal MondayHrs,TueHrs,WedHrs

MondayHrs = 7.30

TuesdayHrs = 7.30

var totahrsinMins =(( Int(MondayHrs)+Int(TusdayHrs)) *60) + (decimal(MondayHrs ) *100) + (decimal(TuesdayHrs ) *100)    Please can you help me to find the formula to find minsinValue

I want to seperate  the integer part  and sum should be multiplied with 60 and seperate the decimal part of the value and multiply with 100

So the result should be

(7+7) * 60 = 840

((.30)*100 ) + (.30*100) = 60

TotalinMinuts = 900  How can I get the formula

• mgebhard

All-Star

53711 Points

24037 Posts

### Re: how can I seperate the integerpart and decimal part

May 30, 2019 10:55 AM|mgebhard|LINK

I assume 7.30 is a base10 value and not 7 hours and 30 minutes.

This is a basic math question 60 minutes in an hour (60m/1h) and 60 seconds in a minute (60sec/1m).  Use the conversion factors to calculate the answer.

7.30h * (60m/1h) = 438 minutes.

Then use modulus to get the left over minutes.

438 % 60 = 18 minutes.  In other words 0.30 hours equals 18 minutes.

• Mikesdotnett...

All-Star

194865 Points

28100 Posts

Moderator

### Re: how can I seperate the integerpart and decimal part

May 30, 2019 11:04 AM|Mikesdotnetting|LINK

You can use the TimeSpan class:

`var MondayHrs = 7.30;`
`var TuesdayHrs = 7.30;`
`var totalMinutes = TimeSpan.FromHours(MondayHrs).TotalMinutes + TimeSpan.FromHours(TuesdayHrs).TotalMinutes;`

I have also assumed that .30 represents 0.3 of an hour (18 mins) rather than 30 mins.

• polachan

Member

414 Points

1339 Posts

### Re: how can I seperate the integerpart and decimal part

May 30, 2019 11:05 AM|polachan|LINK

I applied the following formula

var loghrMins = ((int)log.NormalHrs * 60) + (int)(((decimal)log.NormalHrs % 1) * 100) +
((int)log.SickHrs * 60) + (int)(((decimal)log.SickHrs % 1) * 100) +
((int)log.HolidayHrs * 60) + (int)(((decimal)log.HolidayHrs % 1) * 100) +
((int)log.DayOffHrs * 60) + (int)(((decimal)log.DayOffHrs % 1) * 100) +
((int)log.FuneralHrs * 60) + (int)(((decimal)log.FuneralHrs % 1) * 100) +
((int)log.TimeOffHrs * 60) + (int)(((decimal)log.TimeOffHrs % 1) * 100) +
((int)log.MaternityHrs * 60) + (int)(((decimal)log.MaternityHrs % 1) * 100);

var netHrsMins = ((int)log.NetHrs * 60) + (int)(((decimal)log.NetHrs % 1) * 100);

Is there any other formula to apply better than mine

• mgebhard

All-Star

53711 Points

24037 Posts

### Re: how can I seperate the integerpart and decimal part

May 30, 2019 01:23 PM|mgebhard|LINK

#### polachan

I applied the following formula

var loghrMins = ((int)log.NormalHrs * 60) + (int)(((decimal)log.NormalHrs % 1) * 100) +
((int)log.SickHrs * 60) + (int)(((decimal)log.SickHrs % 1) * 100) +
((int)log.HolidayHrs * 60) + (int)(((decimal)log.HolidayHrs % 1) * 100) +
((int)log.DayOffHrs * 60) + (int)(((decimal)log.DayOffHrs % 1) * 100) +
((int)log.FuneralHrs * 60) + (int)(((decimal)log.FuneralHrs % 1) * 100) +
((int)log.TimeOffHrs * 60) + (int)(((decimal)log.TimeOffHrs % 1) * 100) +
((int)log.MaternityHrs * 60) + (int)(((decimal)log.MaternityHrs % 1) * 100);

var netHrsMins = ((int)log.NetHrs * 60) + (int)(((decimal)log.NetHrs % 1) * 100);

Is there any other formula to apply better than mine

Your calculation assumes 0.30 is 30 minutes while the thread responses assume 30/100.  Your calculation is fine as long as 0.30 means 30 minutes.