How To : Printing Float Numbers ?

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 ..
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
I repeat: floats and doubles don't have the precision oamsath is asking for
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.
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.
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.

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/
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
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.
What could you possibly need to be that accurate for? And how do you know that that is in fact the answer?
mcleano: bc program:
scale=100
5.1234^15
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.