开发者

double or float [duplicate]

This question already has answers here: Closed 11 years 开发者_如何转开发ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜