When to use a Float

前端 未结 7 1049
南笙
南笙 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:02

    The most common reason I could think of is to save space. Not that this is often worth worrying about, but in some instances it matters. A float takes up half as much memory as a double, so you can get twice as many in the same space. For example, I've had an array of numbers that was too big to fit into RAM as doubles but fit as an array floats.

提交回复
热议问题