Welcome to %s forums

BrainModular Users Forum

Login Register

FastScript - Rounding to specified decimal place

I need help on a Patch
Post Reply
sephult
Member
Posts: 1144
Contact:

Unread post by sephult » 20 Nov 2013, 16:51

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
"Every act of creation is first an act of destruction." -Picasso

ynohtna
Member
Posts: 36
Location: Brighton, UK
Contact:

Unread post by ynohtna » 21 Nov 2013, 12:10

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 46 guests