We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › format print(float)
Page Index Toggle Pages: 1
format print(float) (Read 865 times)
format print(float)
May 20th, 2007, 10:19am
 
How to print/format a float value ?

a=123.4305474;
print(a); // output is 123.43055

What if I want 123.4305474 or 123.4 ?

is there a simple way ?
something like print(a:1); to get 123.4 ?
Re: format print(float)
Reply #1 - May 20th, 2007, 11:55am
 
Have a look at http://processing.org/reference/nf_.html
Re: format print(float)
Reply #2 - May 21st, 2007, 4:35am
 
Thanks,
the functions nf(), nfs(), nfp(), nfc() will help.

I didn't know about them (and more...) cause I was always checking the 'Abridged' Reference page.

So if
a=123.4305474,
then
print(sf(a,3,2));
will print
123.43
Page Index Toggle Pages: 1