Time Calculation on Custom Crew Report
I am working on customizing some crew reports that will calculate time, and I am running into an issue with rounding. The results are always rounded to the hour.
For example
Start 23/01/2020 8:00AM, End 23/01/2020 8:30PM gives me a result of 12 hours
The expression I am using is:
($F{alt_end_date}. getTime()-$F{alt_start_date}.getTime())/(1000*60*60) + " hours"
If I remove the calculation to convert from ms to hours I get the correct result. The above example gives me 45,000,000
Any insight would be appreciated
-
Hi Chris-
Is there a pattern on your result text element? If so, if it's something like #,##0 that could be causing the rounding. Replace with #,##0.00 to specify how many decimal places you want to see. Or maybe the result is an integer rather than a Double or a Long?
If you're stuck you can email me at bigs@squarewave.com.au. I'm an endorsed independent consultant and report developer.
Cheers
Bigs
-
Hey Bigs,
Thanks for the quick reply. I tried changing the pattern, which gives me the decimal places, however those are showing up as 0.
I am not sure if the result is an integer. I tried using
LONG_VALUE(($F{alt_end_date}. getTime()-$F{alt_start_date}.getTime())/(1000*60*60) + " hours" )
but it breaks the report. Same with Double
Please sign in to leave a comment.
Comments
3 comments