Solved

# convert minutes to hours and check if entering less then 60 minutes

Posted on 2009-07-16
286 Views
I want to convert minutes to hours by entering a value in minutes, however if I enter a value less then 60 minutes then I get zero

Here is my code snippett

decimal Cost = (Minutes / 60 * hourRate);

what am i doing wrong

0
Question by:mugsey

LVL 14

Accepted Solution

flob9 earned 500 total points
ID: 24867890
try this :

decimal Cost = (((decimal)Minutes) / 60 * ((decimal)hourRate));
0

LVL 85

Expert Comment

ID: 24870682
You could also use the TimeSpan.FromMinutes() method like this:

int Minutes = 45;
decimal hourRate = 10.25M;
decimal Cost = (decimal)TimeSpan.FromMinutes(Minutes).TotalHours * hourRate;
MessageBox.Show("Cost = " + Cost.ToString());

See: http://msdn.microsoft.com/en-us/library/system.timespan.fromminutes.aspx
0

## Featured Post

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be \$37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…