Number precision

Hi,
I want to be able to change the precision of a number every loop cycle.
For example,
loop cycle 1
0.01
loop cycle 2
0.001
loop cycle 3
0.0001
etc..
I hope this makes sense.
Thanks
[285 byte] By [jdm2104] at [2007-11-19 19:43:05]
# 1 Re: Number precision
how about

for ( double x=0.01; condition; x /= 10.0 )
{
// etc.
};
NMTop40 at 2007-11-9 0:57:41 >
# 2 Re: Number precision
Thanks didn't realise it was as easy as that!
jdm2104 at 2007-11-9 0:58:42 >
# 3 Re: Number precision
oops
sreehari at 2007-11-9 0:59:41 >
# 4 Re: Number precision
try this
did u checked what is the output of your Program and what is the actual question.

One more way is

double ft = 12345;
for (int i = 100000,j=5; j >=0 ; j--,i=i/10)
//5 is the total digit of ft so first calculate total digit then perform calculation and that according to that set the value of i
{
printf("%.5f",ft/i);
printf("\n");
}
getch();

output willbe
0.12345
1.2345
12.345
123.45
1234.5
12345.0
humptydumpty at 2007-11-9 1:00:41 >
# 5 Re: Number precision
not sure if this is what your lookin for

int main()
{
double num = 1.1111111111;
int sp = 10;
do {
sp -= 1;
num += 1;
cout << setprecision(sp);
cout << num << endl;
} while (num < 10);
return 0;
}

output reads as

2.11111111
3.1111111
4.111111
5.11111
6.1111
7.111
8.11
9.1
1e+001
80Degrees at 2007-11-9 1:01:48 >