Page 1 of 1

Posted: 20 Nov 2013, 16:51
by sephult
I was wondering if there were any built in functions for rounding to the specified decimal place of a floating point value?
I understand the round and trunc now, but these only seem to operate to the whole number.

I know I will probably have to create my own function, but did not want to reinvent the wheel. Also this might be something that could be added to the built-in round function, like passing the decimal place argument before the value.
If it doesn't exist I will create a feature request, as I believe I will be needing this quite a bit.

Example: round(4,value) rounds the number to the 4th decimal place.


-S

Posted: 21 Nov 2013, 12:10
by ynohtna
Ugly method: format the number as a string with the appropriate DP flags and then convert back.
Common method: multiply the input value by 10^DP, round/trunc/ceil it, then divide it by 10^DP again.