如何获得小时百分比......? [英] How to get the percentage of hours…?
本文介绍了如何获得小时百分比......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用asp.net c#开发一个Web应用程序。在那我需要得到时间的百分比。
我没有得到正确的方法来实现这一目标。我有来自db的TotalHours。
我需要计算TotalHours的80%。
请帮帮我。谢谢你的建议.....
I am developing a web application using asp.net c#. In that I need to get the percentage of Time.
I am not getting the correct way to accomplish this. I have TotalHours which is coming from db.
I need to calculate the 80% of that TotalHours.
Please help me. Thanks in adv.....
TimeSpan TotalTime = TimeSpan.Parse(totalhours);
if(TotalTime != null)
{
TimeSpan Percentage= ( TotalTime* 80 ) / 100;
// here I need to get correct percentage in hrs
// If TotalTime is 10 hrs then Percentage should be 8 hrs
}
推荐答案
你可以使用TotalHours
属性TimeSpan
you can useTotalHours
property ofTimeSpan
TimeSpan TotalTime =(DateTime.Now.AddHours(10)-DateTime.Now); // sample code give you 10 hours for testing
double Percentage =hours.TotalHours*.8; // for above value you will get 8 as percentage
这篇关于如何获得小时百分比......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文