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 › Losing decimal places
Page Index Toggle Pages: 1
Losing decimal places (Read 1933 times)
Losing decimal places
May 31st, 2010, 12:57pm
 
Hello,
I've got a problem.
In one of my programs, I need variables with more than 10 decimal places.
No matter what I do, my variables always lose their decimal places except one.
I tried out float and double, I even googled for help, but I just can't find a way to fix that.
Is there one?
Thanks in advance
emp
Re: Losing decimal places
Reply #1 - May 31st, 2010, 1:46pm
 
show us code. should only take a few lines to illustrate the problem.

my feeling is that println is only showing 10 decimal places but the value being stored is longer than that. either that or it's the old integer division problem.

double d = 1.0f / 9;
println(d);

displays
0.1111111119389534
Re: Losing decimal places
Reply #2 - May 31st, 2010, 2:54pm
 
They're there.

Just use nf() or something like that when printing them.

Code:
float f = exp(1.0);

println(f);
println(nf(f, 1, 10));
Re: Losing decimal places
Reply #3 - Jun 1st, 2010, 4:46am
 
Thanks, now it works.
Lg
emp
Page Index Toggle Pages: 1