Forums > MaxMSP

Removing trailing zeros from symbols

March 13, 2013 | 11:13 pm

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. –

March 14, 2013 | 7:02 am

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. –

March 14, 2013 | 4:04 pm

Awesome, thanks Jeremy! Exactly what I needed.


Viewing 3 posts - 1 through 3 (of 3 total)