Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Thread Tools Search this Thread Rate Thread
Old 11-Jun-2004, 20:40
BobbyMurcerFan BobbyMurcerFan is offline
Join Date: May 2004
Posts: 103
BobbyMurcerFan is on a distinguished road

When to Use Double vs Float?

Is there a rule of thumb for when to use a double vs. a float? I imagine it has to do with size and precision, but I'm not sure how make an intelligent choice between the two.

Also, it seems some fractions are easier to represent in binary than others. So I don't think it's just a matter of how many decimal places but also what actual value you are trying to store.

Nonetheless, I will be representing numbers up to in the tens of thousands with up to 3 decimal places, i.e. nn,nnn.nnn

Float uses 4 bytes and double 8 bytes with my compiler.

Old 12-Jun-2004, 00:18
tay's Avatar
tay tay is offline
Junior Member
Join Date: Jan 2004
Posts: 77
tay will become famous soon enough
float with precision total is 7 digit.
double with precision total is 15 digit.

If you want to control the decimal or precision, you can use:

setprecision ( 2 ) // only 2 decimal , e.g 12.22 setprecision ( 3 ) // 12.333

but you must #include <iomanip>

For your case, you just use 10,000 already 5 digit, and I not sure how many decimal you want. If 2 still can use float, if 3 must use double.

In case your decimal is 2, your digit may be more than 8, so you better use double.
challenges are make life interesting,
overcome them is make life meaningful.
Old 13-Jun-2004, 14:00
BobbyMurcerFan BobbyMurcerFan is offline
Join Date: May 2004
Posts: 103
BobbyMurcerFan is on a distinguished road
Thank you VERY MUCH

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in solving this C++ problem..... homz C++ Forum 3 24-May-2004 22:04
Can somebody look at this and point out any errors to me soulfly C Programming Language 7 31-Mar-2004 10:45
Please Help, problems writing c program REVISED soulfly C Programming Language 6 03-Mar-2004 14:57
string to double C++ calculus87 C++ Forum 2 18-Sep-2003 11:50

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:43.

vBulletin, Copyright © 2000 - 2018, Jelsoft Enterprises Ltd.