Rounding double to x decimals?
TBear
24 Jan 2016, 14:49Hi.
I need to display some doubles in the status attribute window. Problem is that they're super long and ugly. How can I make a double have fewer decimals, preferably still as a double, but as a string would be fine as well.
Thanks.
I need to display some doubles in the status attribute window. Problem is that they're super long and ugly. How can I make a double have fewer decimals, preferably still as a double, but as a string would be fine as well.
Thanks.

jaynabonne
24 Jan 2016, 18:00Here's a function that rounds to the specified number of decimal places and returns the result as a string:
If you want it as a double still, just remove the ToString (and change the function type).
<function name="RoundToPlaces" parameters="value, places" type="string">
scale = pow(10,places)
return (ToString(round(value*scale)/scale))
</function>
If you want it as a double still, just remove the ToString (and change the function type).