Digits in a Number

aywho's icon

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.

Roman Thilenius's icon

you could simply calculate it with if, expr, split ...
(if >9999 and

aywho's icon

sorry, i might be misunderstanding the condition
does this expression (if >9999 and

Wesley Smith's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Try the above.
wes

aywho's icon

That works like a charm!
It's a lot simpler than what I imagined...

Thanks a bunch~

Wesley Smith's icon

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~
>

nick rothwell | project cassiel's icon

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://
www.cassiel.com

Peter Castine's icon

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

Jean-Francois Charles's icon
jasch's icon

i use this
(as wes already mentioned)

Max Patch
Copy patch and select New From Clipboard in Max.
dalinnen's icon

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