Forums > MaxMSP

### Digits in a Number

Nov 15 2006 | 4:33 am

Hi,

Does anyone know if there’s a way to find out the # of digits in a numeric value (i.e. 12 would yield 2, 1940 would yield 4) Any Max object that would do a "strlen" type manipulation?

Thanks a lot.

Nov 15 2006 | 4:57 am

you could simply calculate it with if, expr, split …
(if >9999 and <99999 =5)

Nov 15 2006 | 5:11 am

sorry, i might be misunderstanding the condition
does this expression (if >9999 and <99999 =5) mean something like checking the number to see if it's larger than 9999 and smaller than 9999?

Nov 15 2006 | 5:21 am

#P window setfont "Sans Serif" 9.;
#P number 194 181 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 194 160 34 196617 zl len;
#P newex 194 138 40 196617 atoi;
#P number 194 114 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 2 0 3 0;
#P connect 1 0 2 0;
#P connect 0 0 1 0;
#P window clipboard copycount 4;

Try the above.
wes

Nov 15 2006 | 5:28 am

That works like a charm!
It’s a lot simpler than what I imagined…

Thanks a bunch~

Nov 15 2006 | 5:34 am

BTW, Jasch has wrapped all of the strcmp, strlen etc. objects. Check out:
http://maxobjects.com/?v=libraries&id_library=14&requested=jasch&operateur=AND&id_plateforme=0

wes

On 11/14/06, Angelini wrote:
>
> That works like a charm!
> It’s a lot simpler than what I imagined…
>
> Thanks a bunch~
>

Nov 15 2006 | 9:37 am

On 15 Nov 2006, at 04:33, Angelini wrote:

> Does anyone know if there’s a way to find out the # of digits in a
> numeric value (i.e. 12 would yield 2, 1940 would yield 4) Any Max
> object that would do a "strlen" type manipulation?

The mathematical solution would be something like 1 + trunc(log10
(N)), although that will probably do the wrong thing for values less
than 1. What action do you want for negative numbers?

— N.

nick rothwell — composition, systems, performance — http://
http://www.cassiel.com

Nov 15 2006 | 12:58 pm

tosymbol -> spell -> [t b] -> counter -> numbox

For instance. The number triggering tosymbol would also need to reset
the counter to zero.

Salt to taste.

On 15-Nov-2006, at 5:33, Angelini wrote:

>
> Hi,
>
> Does anyone know if there’s a way to find out the # of digits in a
> numeric value (i.e. 12 would yield 2, 1940 would yield 4) Any Max
> object that would do a "strlen" type manipulation?
>
>
> Thanks a lot.
>

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

Nov 15 2006 | 2:03 pm

Nov 15 2006 | 2:57 pm

i use this

#P newex 103 93 37 196617 strlen;
#P number 103 118 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 103 69 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 2 0 1 0;
#P connect 0 0 2 0;

http://www.jasch.ch/dl

Nov 16 2006 | 1:40 am

just one more standard object, one-box solution. it also accounts for symbols:

jstrigger (String(a).length)

and if you don’t need symbols, you could add an absolute value function to handle negatives correctly:

jstrigger (String(Math.abs(a)).length)

neither is recommended for floats…

–dave linnenbank

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

Forums > MaxMSP