How to format numbers for print()... is javascript different to C?


I couldn't find anything in the docs about using the print() function. I googled for a javascript reference which said that javascript print() uses the same syntax as for C printf(), but that doesn't seem to work in Unity. Can anyone point me to some docs for numeric precision syntax (%.2f etc.)?

In a nutshell, how would I format this C statement for Unity?

printf("%s is %d and thinks pi = %.2f", "Dave", 42, 3.14159);

( Should print: Dave is 42 and thinks pi = 3.14)



print only takes a single string. If you want more printf style input, use String.Format like this:

print( String.Format("{0} is {1} and thinks pi = {2:F2}", "Dave", 42, 3.14159) );

Documented here:

And info on numeric formatting for it here: