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
    • Nov 15 2006 | 5:11 am
      sorry, i might be misunderstanding the condition does this expression (if >9999 and
    • Nov 15 2006 | 5:21 am
      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:// 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 (as wes already mentioned)
    • 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