## A Quick Question.

Mar 25, 2008 at 6:21pm

# A Quick Question.

Hey there!

A Quick questions for you fine people…

1) I have a weight sensor hooked up to Max MSP that is giving me more accuracy than I require. How do I take floating numbers with many decimal places and reduce it to two or three?

Thanks a Bunch!

SMHS

#36513
Mar 25, 2008 at 7:34pm

This might help?

max v2;
#N vpatcher 14 59 614 459;
#P window setfont “Sans Serif” 9.;
#P number 191 242 103 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 245 117 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 245 140 44 196617 t b i i;
#P newex 184 181 27 196617 pow;
#P newex 184 144 36 196617 t 10 f;
#P newex 191 216 29 196617 * 1.;
#P button 184 63 15 0;
#P newex 184 90 21 196617 t 9;
#P newex 184 120 27 196617 / 7.;
#P flonum 210 182 171 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 283 119 168 196617 Number Of Decimal Places required;
#P fasten 8 0 4 0 250 164 230 164 230 61 189 61;
#P connect 4 0 3 0;
#P connect 3 0 2 0;
#P connect 2 0 6 0;
#P connect 6 0 7 0;
#P fasten 7 0 5 0 189 208 196 208;
#P connect 5 0 10 0;
#P fasten 8 1 7 1 267 172 206 172;
#P connect 6 1 1 0;
#P connect 1 0 5 1;
#P connect 9 0 8 0;
#P pop;

#125407
Mar 25, 2008 at 8:04pm

try [sprintf %.2f] where ’2′ is the number of desired decimals.

-ben b.

Brent Huras wrote:
> Hey there!
>
> A Quick questions for you fine people…
>
> 1) I have a weight sensor hooked up to Max MSP that is giving me more accuracy than I require. How do I take floating numbers with many decimal places and reduce it to two or three?
>
> Thanks a Bunch!
>
> SMHS
> –
> Love (But Just as Friends),
> Stealth Maestro
>

#125408
Mar 26, 2008 at 12:58pm

Yet another solution: multiply input by 10^(desired number of decimal places); convert to integer (truncate or round as desired); divide by 10^(num-dec-place).

But note that this is largely all eye candy: Max is using 32-bit floating point, which cannot store 3.14 any more or less accurately than it stores 3.1400000625.

In a number of situations flonum will keep things to 2 sig digits after the decimal point. Otherwise sprintf is a good approach for eye candy.

– P.

#125409

You must be logged in to reply to this topic.