Removing trailing zeros from symbols

Mar 13, 2013 at 11:13pm

Removing trailing zeros from symbols

How do I remove trailing zeros that sprintf is generating from ints going to symbols? Probably really simple, just never needed to know. I already searched, and couldn’t find the answer.

0.29 becomes 0.290000

I want to remove the last four zeros but keep it a symbol. regexp?

Problem:

– Pasted Max Patch, click to expand. –
#67069
Mar 14, 2013 at 6:58am

Hi,

The type coercion in MaxMSP is not always easy to deal ; you can not easily avoid a number as a string to be cast to a number as a float (and floating point consequences related). In a precise scenario (what is it for ?) it can have some tips an tricks, but in general don’t rely on that.

http://cycling74.com/forums/topic.php?id=45059

#241376
Mar 14, 2013 at 7:02am

Try the attached. The solution on the left won’t work for all numbers (very small numbers will be displayed in exponential notation), but for most in the range you’ll be using for display in Max, it should be fine. The solution on the right should work for all numbers, but is certainly a little slower.

http://stackoverflow.com/questions/2411903/getting-printf-to-drop-the-trailing-0-of-values
http://stackoverflow.com/questions/1863602/floating-point-formatting-in-printf

http://www.manpagez.com/man/3/printf/

Best, Jeremy

– Pasted Max Patch, click to expand. –
#241377
Mar 14, 2013 at 7:27am

Hi,

Good to know, thanks ;-)

With MaxMSP 5.1.9 it seems to be [regexp 0+?$ @substitute %0 @tosymbol 1].

– Pasted Max Patch, click to expand. –
#241378
Mar 14, 2013 at 4:04pm

Awesome, thanks Jeremy! Exactly what I needed.

#241379

You must be logged in to reply to this topic.