When to use a Float

前端 未结 7 1048
南笙
南笙 2021-02-03 18:40

Years ago I learned the hard way about precision problems with floats so I quit using them. However, I still run into code using floats and it make me cringe because I know som

7条回答
  •  失恋的感觉
    2021-02-03 19:15

    Short answer: You only have to use a float when you know exactly what you're doing and why.

    Long answer: floats (as opposed to doubles) aren't really used anymore outside 3D APIs as far as I know. Floats and doubles have the same performance characteristics on modern CPUs, doubles are somewhat bigger and that's all. If in doubt, just use double.

    Oh yes, and use decimal for financial calculations, of course.

提交回复
热议问题