converting integers to symbols with leading zeroes

Dec 13, 2007 at 7:37pm

converting integers to symbols with leading zeroes

hi ppl,
i have a question regarding integer-conversion and leading zeroes. my aim is to convert 4 number box contents to a symbol that is eg. “09″ and not “9″ in the case of numeric values lower than 10. is there something out there or can anyone help out with this?

example:
1 2 3 4 => 01020304
10 4 15 60 => 10041560

any ideas?

thanks!

#35002
Dec 13, 2007 at 7:45pm

Lots of examples of this, including very recently, in the forum
archives – have a search there.

Meanwhile – [sprintf] is your friend.

On Dec 13, 2007, at 12:37 PM, Matthias Tarasiewicz wrote:

>
> hi ppl,
> i have a question regarding integer-conversion and leading zeroes.
> my aim is to convert 4 number box contents to a symbol that is eg.
> “09″ and not “9″ in the case of numeric values lower than 10. is
> there something out there or can anyone help out with this?
>
> example:
> 1 2 3 4 => 01020304
> 10 4 15 60 => 10041560
>
> any ideas?

—-
Steven M. Miller
Professor, Contemporary Music Program
College of Santa Fe

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>
CMP <
http://www.csf.edu/csf/academics/cmp/index.html>

#118791
Dec 13, 2007 at 9:31pm

#118792
Dec 15, 2007 at 6:22pm

thank you all for your replies.
in the end i solved it with javascript, here is the result:

function foo(a,b,c,d)
{
r=”"
if (a<10) { a="0"+a}
if (b<10) { b="0"+b}
if (c<10) { c="0"+c}
if (d<10) { d="0"+d}
outlet(0,r.concat(a,b,c,d));
}

sending a packed message with foo $1 $2 $3 $4 does the trick. Roby, thanks for the pointer to your object, that also looks very nice…

#118793
Dec 15, 2007 at 9:58pm

#118794

You must be logged in to reply to this topic.