double or float [duplicate]
Possible Duplicate:
Should I use double or float ?
When would I rather use double and when should I use float?
It's all about precision.
If you need to store very precise numbers then use a double.
If you need to store less precise numbers and are worried about the size of memory you're using then use a float.
The only time you need to use float
is when you are storing large arrays of numbers. There is generally little difference in speed between the two and natively most things are double
anyway.
Use double
when you require the range it supports. Refer to Range of floating-point numbers. You should also typically use the native type, so if you're doing graphics or GPU programming, probably better stick to floats.
But whatever you do, please, do not use either to represent currency or money.
精彩评论