I have problem formatting double number. When double number is stored in computer(binary representation), it is not exact as decimal representation. when I try to format the double number with more decimal points(ex- 12) then as number gets bigger, I get more and more noise which makes number look different than the one entered as decimal number. How can I find the way to format the number so I do not see noise? or How can I find out how many decimal points I can safely show without getting noise for any double number? thanks...

09-19-2001

lmov

double is a floating point data type. What this means is that the decimal point is not fixed at some position, but moves as necessary. If you're having problems aligning numbers on the screen, try something like this:

Code:

#include <cstdio>

int main()
{
double d[] = { 5.5, -12.599, 124.42112 };
int i;

// Loop through all elements of the array
for(i = 0; i < sizeof(d) / sizeof(d[0]); i++)
// %9.5f specifies that a double is being passed,
// which should be formatted to be at least 9
// characters long with 5 characters after the
// after the decimal point.
printf("%9.5f\n", d[i]);