如何以时间格式显示十进制值 [英] how to show decimal value in time format

查看:102
本文介绍了如何以时间格式显示十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有工作时间的员工。喜欢

小时1 = 8.0

小时2 = 10.5



现在要获得小时数,我首先乘以小时用60手然后用分针加总。

sum =(总和+(hh * 60)+ mm);



现在总时数除以60

sum = Math.Round(sum / 60,2);



,结果是

sum = 18.83



现在我想显示18.83像18.5





请给我任何解决方案。





谢谢。

解决方案

你应该使用 TimeSpan s。

这样:

< pre lang =c#> TimeSpan ts1 = TimeSpan.FromHours( 8 );
TimeSpan ts2 = TimeSpan.FromHours( 10 5 );
TimeSpan total = ts1 + ts2;
MessageBox.Show(total.TotalHours.ToString());


如何使用DateTime类?

http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ]



它有你想要的所有方法......


看看这个:



http:// stackoverflow.com/questions/5852305/c-sharp-string-format-for-hours-and-minutes-from-decimal [ ^ ]



http://stackoverflow.com/questions/1345599/how-to-convert-decimal-number-to-time-or-vice-versa/1345634#1345634 [ ^ ]


Hi,
i have working hours of employee. Like
hours1=8.0
hours2=10.5

Now to get sum of hours,i first multiply hours hand with 60 and then sum it with minutes hand.
sum = (sum + (hh * 60) + mm);

Now to get total hours divided sum by 60
sum = Math.Round(sum / 60, 2);

and the result is
sum=18.83

Now i want to display 18.83 like 18.5


Please give me any solution if any will have.


Thanks.

解决方案

You should use TimeSpans.
This way:

TimeSpan ts1 = TimeSpan.FromHours(8);
TimeSpan ts2 = TimeSpan.FromHours(10.5);
TimeSpan total = ts1 + ts2;
MessageBox.Show(total.TotalHours.ToString());


How about using the DateTime class instead?
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^]

It has all the methods that you want...


Look at this:

http://stackoverflow.com/questions/5852305/c-sharp-string-format-for-hours-and-minutes-from-decimal[^]

http://stackoverflow.com/questions/1345599/how-to-convert-decimal-number-to-time-or-vice-versa/1345634#1345634[^]


这篇关于如何以时间格式显示十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆