calc minutes to houre

time calc problem
i have this resuat of time :
its need to be 11 hours
the .60 is minutes
its need to be turn to 1 houre
i do this code ant its work good :

decimal time =(decimal)10.60;
decimal t = time % 2;
textBox2.Text = t.ToString();
decimal res =(t/60) * 100;
time = time - t;
decimal tot = time + res;

now if the total hour is 10.70 insted of 10.60
i need to get 11 hours and 10 min = 11.10
i am geting wrong resualt 11:16

how can i fix that ?
thanks ...
Who is Participating?
JimBrandleyConnect With a Mentor Commented:
This will do what you want:
decimal time = (decimal)10.70;
int hours = (int)time;
time = time - hours;
int minutes = (Convert.ToInt32(time * 100));
int extraHours = minutes / 60;
minutes = minutes % 60;
int totalHours = hours + extraHours;
time = Convert.ToDecimal(totalHours) + Convert.ToDecimal(minutes ) /100;

Generally what are you using this code for? what are you trying to do ?
Tech_MenAuthor Commented:
i mange but i still have a small problem
if the diff is a round number
i need to add the number .00

i need to check if the num is round and if he is round i need to attach the .00
if i get the num 8
i need to change it to 8.00
If you are looking to check if the number is round. you should look at Math.Round() function
Tech_MenAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.