Converting hours in decimal format
java
Solution
- There is no need to do a modular on minutes.
Your calculation of minutes should just multiply by 60, not (60*60)
double finalBuildTime = 10.89;
int hours = (int) finalBuildTime;
int minutes = (int) (finalBuildTime * 60) % 60;
int seconds = (int) (finalBuildTime * (60*60)) % 60;
System.out.println(String.format("%s(h) %s(m) %s(s)", hours, minutes, seconds));
This code gives you the correct output
10(h) 53(m) 24(s)
I believe your expected output of 40 seconds is incorrect. It should be 24 seconds.
(53*60 + 24)/(60*60) = 0.89
Problem
I've tried mutliple solutions to this problem but I can't seem to get it. I have time in decimal format, which is in hours. I want to make it much cleaner by changing it into a DD:HH:MM:SS format. Example: 10.89 hours == 10 hours, 53 minutes, 40 seconds EDIT: 10.894945454545455 == 10 hours, 53 minutes, 40 seconds What I've tried: ``` int hours = (int) ((finalBuildTime) % 1); int minutes = (int) ((finalBuildTime * (60*60)) % 60); int seconds = (int) ((finalBuildTime * 3600) % 60); return String.format("%s(h) %s(m) %s(s)", hours, minutes, seconds); ``` Which returned: `0(h) 41(m) 41(s)` Any suggestions?