Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have total of hours and minutes and rate , so how can i get totalmoney
i tryied some codes but the result is deferent to calculator;
C#
protected double ConvertTo100(string strTemp)
        {
            strTemp = strTemp.Replace(':', '.');
            
            double dblTemp;
            dblTemp = Convert.ToDouble(strTemp);
 
            double dblHH = Math.Floor(dblTemp);
            double dblMM = Math.Round(dblTemp - Math.Floor(dblTemp), 2) * 60 / 100;
 
            double dboReturn;
            dboReturn = dblHH + dblMM;
            return dboReturn;
        }
than i use this funcation like..

	DGTotalMoney.DigitText = Convert.ToString( ConvertTo100(DGHours.DigitText + ":" + DGMinutes.DigitText) * (double.Parse(CBlistPrice.Text)));

and i tried this code too:
C#
DGTotalMoney.DigitText = Convert.ToString( ConvertTo100(DGHours.DigitText + ":" + DGMinutes.DigitText) * (double.Parse(CBlistPrice.Text)));

but the result is deferent?
so i need help
Posted
Comments
MuhammadUSman1 27-Jun-13 0:50am    
What your method should return if we give "0.30" value in parameter?
What is your requirement?

Or give some dummy values as input value and there expected results?
MuhammadUSman1 27-Jun-13 0:55am    
I have added solution please check it.

if any confusion. Let me know?

Your code is operating on the minutes portion of the HH:mm string incorrectly. If it was 30 mins, it should return 0.5. Your code for 30 mins returns 0.18.
 
Share this answer
 
C#
protected double ConvertTo100(string strTemp)
        {
            strTemp = strTemp.Replace(':', '.');

            double dblTemp;
            dblTemp = Convert.ToDouble(strTemp);

            double dblHH = Math.Floor(dblTemp);

            double dblMM = Math.Round(dblTemp - Math.Floor(dblTemp), 2) * 100 / 60; //i changed this line 

            double dboReturn;
            dboReturn = dblHH + dblMM;
            return dboReturn;
        }


as _Damian S_ said if we give "0.30" as input value it's result will be "0.5".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900