Truncate to specific number of decimal places?

2074
5
Jump to solution
07-08-2021 08:32 PM
JulietK
Occasional Contributor II

Hi, I'm looking for a way to truncate the value of a decimal field type question to 2 decimal places. I've tried Google search but it seems like all I can find is methods of rounding..

For e.g. I get a number from a calculation that is 1.1495. I would like to have another field with a calculation truncate this to 1.14, not round it to 1.15. Is there a truncate formula available for xlsforms? 

The values I get could range from 1.0 to 1,000,000.0 so I don't think I would be able to use concat().

Thanks for your help!

0 Kudos
1 Solution

Accepted Solutions
JayantaPoddar
MVP Esteemed Contributor

Something like this could work.

round(${question_one}-0.005, 2)


Think Location

View solution in original post

0 Kudos
5 Replies
JayantaPoddar
MVP Esteemed Contributor

Something like this could work.

round(${question_one}-0.005, 2)


Think Location
0 Kudos
JulietK
Occasional Contributor II

Thank you for your response! I think this would work if the initial value from the calculation field was always 3 decimals; however the value could range anywhere from 0 decimal places to 5+ decimal places.

OR, I might need to do some testing to see if this would give consistent results for values with more than 3 decimal places. Thank you again

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

It should work for all floating numbers for rounding down to 2 decimal places. Let me know if there is any concern.

e.g.

15: (15-0.005)= 14.995= 15.00= 15

15.99925: (15.99925-0.005)= 15.99425= 15.99



Think Location
LisaDygert
Occasional Contributor
0 Kudos
JulietK
Occasional Contributor II

Thank you for your response! Unfortunately inputmask doesnt work on web forms, and I dont think regex would work if the value is automatically coming from a calculation in another field rather than being manually entered by the submitter...

0 Kudos