Why does 49.90 % 0.10 in JavaScript return 0.09999999999999581? I expected it to be 0.
Why does 49.90 % 0.10 in JavaScript return 0.09999999999999581? I expected it to be 0.
Hopefully this is helpful to someone:
let asBuffer = new ArrayBuffer(8);
let asInt = new Uint32Array(asBuffer );
let asFloat = new Float32Array(asBuffer );
asFloat.set([49.9,.1]);
asInt.set([asFloat[0]/asFloat[1], asFloat[0]%asFloat[1]]);
Result
asInt Uint32Array(2) [499, 0, buffer: ArrayBuffer(8), byteLength: 8, byteOffset: 0, length: 2, Symbol(Symbol.toStringTag): 'Uint32Array']
//In general I'm moving more and more towards
//Using typed arrays to store values in JS.