- deweeseAsked on June 29, 2017 at 05:49 PM
How can you get the decimal correct for result from two times? For example, total hours/mins from a start and end time.
This is a re-post of a comment on How to Perform Form Calculation Using a Widget
- JotForm SupportJim_RAnswered on June 29, 2017 at 07:29 PM
I guess what you're asking is how to extract the decimal places of a calculated result. Perhaps you're getting the difference between 2 Time Fields, and you wanted to show the number of hours and minutes.
Is this the form you're working on 71793741584164?
Here's a cloned copy of it showing how it's done 71797818078979.
Follow these steps to achieve this:
1. Add 2 Form Calculation Widgets below Start Time and End Time, then label them as Hours and Minutes.
2. Set the HOURS formula as shown below:
The floor() function rounds down a number. So regardless of the decimal place, the only value that will be calculated on the HOURS field is the rounded down whole number.
3. Then, the MINUTES formula like so:
This time, the formula looks a bit complicated but it's really straight forward. The round() function was used to round off (not round down) the result.
Basically, you would need to get the decimal places of the difference first. You can get that by subtracting the floored difference from the normal difference.
5.67 - 5 = 0.67
Then, to get the MINUTES equivalent, just multiply it by 60.
- deweeseAnswered on June 30, 2017 at 08:13 AM
Ahh, thanks so much. That makes sense! That worked like a charm.