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 › Any way to set the number of significant figures
Page Index Toggle Pages: 1
Any way to set the number of significant figures? (Read 667 times)
Any way to set the number of significant figures?
Nov 5th, 2009, 12:54pm
 
Hi, I'm trying to display some percentage values, but there are too many significant figures, so they look silly on screen. Is there any way to set the number of significant figures to display for a float when using text()?
Re: Any way to set the number of significant figures?
Reply #1 - Nov 5th, 2009, 12:59pm
 
ps...  I'm currently doing the following, but it ain't pretty:
Code:

text((float)round(1000*(a float like 0.0234845))/10 + "%", x, y)

Re: Any way to set the number of significant figures?
Reply #2 - Nov 5th, 2009, 2:44pm
 
try http://processing.org/reference/nf_.html to format your number to a string
Page Index Toggle Pages: 1