regeXGuru4
regeXGuru4

Reputation: 21

any class to multiply time other than manually multiplying sum of hours and minutes

I'm trying to calculate a pay per hour problem, like for example someone gets 50 dollar per hour and they have worked 5 hours and 45 minutes, what is their pay? I tried to convert it to long and multiply it, it didn't work then tried to divide hour to min and multiply that to the division of the pay which seemed ok by I doubt that,

you can sum two date from Date api but is there any multiply method?

Upvotes: 0

Views: 165

Answers (1)

UkFLSUI
UkFLSUI

Reputation: 5672

This should be a simple mathematics. As you have told that you tried to convert it to long and multiply it, that shouldn't work. As when you convert minutes to hour that will turn into decimal value.

So,

5 hours and 45 minutes = 5 + (45 / 60) hour

In code, it should look like this:

double hourValue = 5 + (45 / 60);
double payment = hourValue * 50;

Upvotes: 1

Related Questions