sprintf question

Sophia's icon

Why does [sprintf string%1i string%1i] evaluate to [string$1 string0]? Similarly [sprintf string%1i string%2i] evaluates to [string$1 string $2]. I figured out I could fix it by doing [sprintf string%1i string%.2i] to get the leading zero, but I don't understand what's going on here.

Luke Hall's icon

I can't reproduce that behaviour. What values are you sending in to the [sprintf] object? To get a leading zero use something like [sprintf symout %04i] where the 4 sets how much padding you want. You can use [sprintf symout %.4f] to apply the padding after a decimal place.

lh

jvkr's icon

Unlike expr, sprintf does not require variables to be designated to specific inlets. Each new variable will create an inlet and the order of inlets is identical to the order of variables. In your specific example, the number 1 in string%1i does not do anything as it is not part of the definition of printf.

_
johan

Sophia's icon

Thanks, Johan. It works fine if I just remove the numbers and send the integer to each inlet.