truncate or round?

yerpzs's icon

hi i have a number coming from a scale

35.2200001

I hope to record this particular number into a coll rounded down to 35.22

so i tried
( round 0.01)
(expr int($f1+($f1>0.)-0.05)
(sprintf .2f)
I even converted the number to an audio signal and used (trunc~)

each of these allowed me to view at 2 decimal places, but when sending into a coll it always records in the coll at 35.2200001. along with all my other numbers.

Is there a way to round up or down a number and record the rounded result into the coll?

thanks



Bill 2's icon

What about x 100. -> int -> x 100. ?

Bill 2's icon

Oops! Make the last object / 100.

ben sonic's icon

and if you want to round a float to the nearest integer instead of truncate it, you can take the round object in the same manner bill suggested:
*100. -> round -> /100.

ben sonic's icon

BTW "round 0.01 " is working on my system, which is even more simpler.

Max Patch
Copy patch and select New From Clipboard in Max.

ben sonic's icon

works even with coll

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

i guess that 35.22 simply does not exist: there is only 35.2200001

so everytime you convert that number first to a symbol and then back to a number, it becomes longer again.

yerpzs's icon

thanks Bill yes i tried x 100. /100. it was still the same.

Thanks Ben i shall try your patch when i am on my max machine tomorrow..

in the mean time , i am just storing the longer numbers and I am just rounding when I view the data.

i've realise i don't actually need to store it rounded up or down it just looked a mess and It was just so puzzling!

yes Roman i tried converting with tosymbol and fromsymbol as well, same result.

I shall still try your patch later on Ben, thanks!!

yerpzs's icon

Great patch Ben

That works fine. It all goes into the coll perfectly.

It looks so simple, but i just could not get it to work.

nice one ! : p