Does JavaScript have double floating point number precision?

前端 未结 3 1097
一个人的身影
一个人的身影 2020-11-29 08:18

I know it\'s an odd question, but does JavaScript have the capacity to work with double\'s as opposed to single floats? (64 bit floats vs. 32 bits.)

3条回答
  •  眼角桃花
    2020-11-29 08:35

    In javascript type number it's float 64-bit number that support IEEE 754 standard and it's like double in C. And you can create 32-bit typed arrays by commands below and control each byte in each component by binding corresponded buffer.

    let a = new Float32Array(length);
    let b = new Float64Array(length);
    

    But note that it's not supported in IE9, here browser compatibility table.

    If you want extended presicion like long double, you can use double.js or decimal.js library.

提交回复
热议问题