Digits in a Number
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.
you could simply calculate it with if, expr, split ...
(if >9999 and
sorry, i might be misunderstanding the condition
does this expression (if >9999 and
Try the above.
wes
That works like a charm!
It's a lot simpler than what I imagined...
Thanks a bunch~
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~
>
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
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
i use this
(as wes already mentioned)
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