Float Precision
no. because then it would be fixed point.
however, you can modify the way the C/C++ functions display floating point numbers.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
however, you can modify the way the C/C++ functions display floating point numbers.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Thanks, allthough my brain doesn''t seem to working today so any help on your suggestion would be really appriciated. Thanks
What do you need this for? Would printing out only 2 decimal points be ok? Use
printf("%.2f\n", my_float);
Math may not work out prefectly all the time though, ie, 1.00 + 1.00 = 1.99
However, this value would probably be 1.99999 internally, so just do some rounding and everything should work fine (unless you add 1.0 500000 times, but then, rounding at each step would solve this).
You could look up fixed point number also, but it''s lightly more complicated.
Round example:
MyAnswer = (1.9999 + 0.005)
printf("%.2f\n", MyAnswer); //prints out 2.00
printf("%.2f\n", my_float);
Math may not work out prefectly all the time though, ie, 1.00 + 1.00 = 1.99
However, this value would probably be 1.99999 internally, so just do some rounding and everything should work fine (unless you add 1.0 500000 times, but then, rounding at each step would solve this).
You could look up fixed point number also, but it''s lightly more complicated.
Round example:
MyAnswer = (1.9999 + 0.005)
printf("%.2f\n", MyAnswer); //prints out 2.00
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement