How To : Printing Float Numbers ?

Jun 30, 2009 at 8:30pm
Hello .. I'm in front of a problem that I'm supposed to print the result of :
5.1234 ^ 15
the result is :
43992025569.928573701266488041146654993318703707511666295476720493953024
using { cout<<variable; } where variable holds the result ..
the problem is the number is printed by scientefic way (exponential) or approximated .. how can I print the full number as it is untill its last digit ?

thanks in advance ..
Jun 30, 2009 at 9:44pm
Jul 1, 2009 at 5:14am
Use statement cout<<fixed<<setprecision(5)<<variable;. Number within () is the no of digits after decimal point.
Check it out. I am a learner so expect errors.
Last edited on Jul 1, 2009 at 5:15am
Jul 1, 2009 at 9:51am
I repeat: floats and doubles don't have the precision oamsath is asking for
Jul 1, 2009 at 3:12pm
O... yes. Few Bytes for float and double variables can not accommodate such a huge number(not wrt value but wrt length), thus precision is lost during calculations.Is it??????????? I think above statement works with available number of digits after decimal pt.
Jul 1, 2009 at 7:38pm
you could try using a long double if your computer has it longer than a double, it will give a few more useless digits at the end of your number.
Jul 1, 2009 at 8:06pm
The number above has 71 digits of precision.

Elementary math...

10^71 = 2^k
71 ln(10) / ln(2) = k
236 = k

You need a floating point data type that has at least 236 bits to dedicate to the mantissa (assuming IEEE format).

No intrinsic floating point type is going to give you that much precision.

Jul 1, 2009 at 11:24pm
You might like to use GNU Multiple Precision Arithmetic Library. If you use this, there is absolutely no limit to the precision.

http://gmplib.org/
Jul 3, 2009 at 3:47pm
thanks all for replying ... but for some idea someone told me that i can store the value in a string and output the string itself, but gave no further explination ..

how can i do that ??

thanks
Jul 4, 2009 at 12:59am
Well, you can't even compute the number to that many digits of precision, let alone output it. Your problem is in the computation of the number, not in the output of it.
Jul 4, 2009 at 1:14am
What could you possibly need to be that accurate for? And how do you know that that is in fact the answer?
Jul 4, 2009 at 1:49am
mcleano: bc program:
scale=100
5.1234^15
Jul 4, 2009 at 10:37am
Sorry this is new to me, have never heard of it before :S

Dont worry I won't ask you to explain it though!
Topic archived. No new replies allowed.