1. ## Scientific notation

Hi! I'm using LONG DOUBLE data types & I get scientific notation starting at a million.

Is there any way to "force" the program to either:

a) DISPLAY it as a regular number
b) CHANGE it to a regular number

Also, I would imagine that there is a loss in precision with scientific notation. Is there a way to calculate numbers on that scale (maybe up to 1E+36) without any loss in precision using C?

Thanks!

mw

2. Well you can tweak the width and precision to get more significant digits out
Code:
```#include <stdio.h>

int main ( void ) {
double d = 12345678901.2345;
printf( "%15.30f\n", d );
return 0;
}```
> Is there a way to calculate numbers on that scale (maybe up to 1E+36) without any loss in precision using C?
In my math.h, I have
#define LDBL_DIG 18
Basically, long doubles can store 18 decimal digits accurately.

Use a math library like this if you want more digits http://www.swox.com/gmp/

3. Uh, I don't understand that "%15.30f" in your printf statement. Can you clarify?

Also, is there a way to display it without a decimal?

Thanks!

mw

4. Originally Posted by Lionmane
Uh, I don't understand that "%15.30f" in your printf statement. Can you clarify?

Also, is there a way to display it without a decimal?

Thanks!

mw
It's just a extra info how the number is formated.
that means: put up to 15 digits on the left side of the point, and up to 30 digit on the right side. something like
000000000000000.000000000000000000000000000000
trailing zeros are disposed.

5. If I change the printf statement to this:

printf ("%15f\n", d);

It still prints 6 digits on the right side of the decimal. Is there a way to print any number of digits to the left side of the decimal & none on the right?

Thanks!

mw

6. Originally Posted by xErath
It's just a extra info how the number is formated.
that means: put up to 15 digits on the left side of the point, and up to 30 digit on the right side. something like
000000000000000.000000000000000000000000000000
trailing zeros are disposed.
Not exactly. It means, "use at least 15 characters to represent the whole shebang, but use 30 digits after the decimal point".
Originally Posted by Lionmane
Is there a way to print any number of digits to the left side of the decimal & none on the right?
Code:
```#include <stdio.h>

int main(void)
{
double d = 12345678901.2345;
printf("d = %45.30f\n", d);
printf("d = %.0f\n", d);
return 0;
}

/* my output
d =     12345678901.23450088000000000000000000000
d = 12345678901
*/```

Code:
```#include <stdio.h>

int main(void)
{
double d = 12345678901.2345;
int any_number = 40;
printf("d = '%45.30f'\n", d);
printf("d = '%*.0f'\n", any_number, d);
return 0;
}

/* my output
d = '    12345678901.23450088000000000000000000000'
d = '                             12345678901'
*/```

7. I hate to beat a dead horse here, but when I use this:

printf ("%45.0f\n", d);

It prints 45 spaces to the left of the decimal whether there are 45 digits or not. Is there a way to truncate the extra spaces?

mw

8. Reread the second output of the first code fragment of my previous reply.

9. Heck yeah! Thanks, man!

mw

10. Originally Posted by Dave_Sinkula
Not exactly. It means, "use at least 15 characters to represent the whole shebang, but use 30 digits after the decimal point".
Yes whatever... tricky english