如何将timespan.totalhours舍入到小数后的两位数 [英] how to round of timespan.totalhours to two digits after decimal
本文介绍了如何将timespan.totalhours舍入到小数后的两位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用TimeSpan.Totalhours我喜欢23.5686565时,我怎么能把它四舍五入到23.56
解决方案
如果你这样做是为了演示目的,你最好使用下面的格式说明符:
TimeSpan.TotalHours.ToString( N2)
请查看 Math.Round [ ^ ]方法 - 但你的例子是不是传统四舍五入 - 这将给23.57而不是23.56。
您可能想要使用 Math.Truncate [ ^ ]将值乘以100.0然后再划分。
试试这个Math.Floor(23.5686565)
Hi when Iam using TimeSpan.Totalhours Iam getting some times hours like 23.5686565 so how can I round it to 23.56
解决方案
If you are doing this for presentation purposes, you're better off using the following format specifier:
TimeSpan.TotalHours.ToString("N2")
Look at the Math.Round[^] method - but your example is not "traditionally" rounded - that would give 23.57 not 23.56.
You may want to use Math.Truncate[^] on the value multiplied by 100.0 and then divided again.
try thisMath.Floor(23.5686565)
这篇关于如何将timespan.totalhours舍入到小数后的两位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文