Sprintf equivalent in Mathematica?
Posted
by jxy
on Stack Overflow
See other posts from Stack Overflow
or by jxy
Published on 2009-10-06T16:18:22Z
Indexed on
2010/04/18
14:33 UTC
Read the original article
Hit count: 221
mathematica
I don't know why Wikipedia lists Mathematica as a programming language with printf. I just couldn't find the equivalent in Mathematica.
My specific task is to process a list of data files with padded numbers, which I used to do it in bash with
fn=$(printf "filename_%05d" $n)
The closest function I found in Mathematica is PaddedForm
. And after some trial and error, I got it with
"filename_" <> PaddedForm[ Round@#, 4, NumberPadding -> {"0", ""} ]&
It is very odd that I have to use the number 4 to get the result similar to what I get from "%05d". I don't understand this behavior at all. Can someone explain it to me?
And is it the best way to achieve what I used to in bash?
© Stack Overflow or respective owner