cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
How to make a long float or something
How to make a long float or something
Aug 29, 2012 at 5:43pm UTC
Ch1156
(1970)
Ok so in my game the player is given a billion dollars to start with, i have
float money = 1000000000;
but when i go to display the money it gives me a weird number: 1e+009
I think its illegal to do a long or unsigned float, i could do an int but i need precise point numbers so what do i do?
I tried unsigned long int and that worked but is there any way to do it with a float?
Last edited on
Aug 29, 2012 at 5:48pm UTC
Aug 29, 2012 at 5:51pm UTC
Athar
(4466)
"long float" is called double, which is what you should use when you need to deal with floating point numbers, unless you have very good reasons to use float.
However, your issue is unrelated to that, it's just the way you print it:
1
2
#include <iomanip>
cout << fixed << setprecision(2) << money << endl;
http://www.cplusplus.com/reference/iostream/manipulators/fixed/
Aug 29, 2012 at 5:53pm UTC
Lowest0ne
(1536)
1e+009 is 1 * 10^9, which is 1 billion.
Topic archived. No new replies allowed.