I need to calculate the cost of the received time, if there is a price for 1 day. I do as follows:

long hoursDays = diff/(60*60*1000); long priceHour = Long.valueOf(etPriceZas.getText().toString()); long result1 = priceHour/24; long result = result1 * hoursDays; 

First, I get the amount of time in hours, then I divide the cost per day by 24 hours and multiply the resulting numbers by each other.

But the trouble is, if I enter the price per day in 1200, then everything is correct, and if 1000 - after all calculations, it gives out - 984 rubles in 24 hours.

How can this be fixed?

    1 answer 1

    Because you use long.

    Here

     long result1 = priceHour/24; 

    in result1 there will be only an integer part (1200/24 ​​= exactly 50, and 1000/24 ​​= integer part 41, and the whole fractional is discarded). If I understand correctly, then instead of long you just need to use float.