Before I go down this rabbit hole further. If you could share your wisdom/experience.
I’m assuming with certain large floating-point numbers is a known problem and CAN NOT be converted to 2 decimal places. As these large numbers appear to be an error, it is the way things work with my current findings as we discuss below.
StackOverflow
Tearing through page after page related to big floating-point numbers devs are trying to find ways of converting. I’d be another duplicate that is why we are discussing on discourse.threejs.org have you come across these big floating-point numbers? What did you do to convert to 2 decimal places?
Dev(s) speak of many ways in trying to do the same thing and yet these numbers refuse to change = typeof number: 0.9299999999999999
Reference: Round to at most 2 decimal places (only if necessary) = none of these worked for my situation
What is really strange is when I convert 0.93 from a string back into 0.93 the computer wants to convert to 0.9299999999999999
ry += Number(((parseFloat(rotateY, 10)).toFixed(2)));
ry += Math.round((rotateY * 100 ))/100;
The 2 pieces of code that fit into line 10 are trying to do the same thing, this is more commonly what you’ll see devs doing because you need to have an understanding that toFixed(2) will produce a string.
ry += Math.round((rotateY * 100 ))/100;
Devs do go on to discuss using:
Input
01 var trigger = setInterval(function() {
02 cnt++;
03
04 var rotateY = THREE.Math.degToRad(18);
05
06 if (cnt < 4) {
07 var works = (ry + parseFloat(rotateY, 10)).toFixed(2);
08 console.log('WORKING AS STRING:', works);
09 console.log(typeof works);
10 ry += Math.round((rotateY * 100 ).toFixed(2))/100;
11 console.log('FIXED AS NUMBER:', ry);
12 console.log(typeof ry);
13 }
14 if (cnt === 11) {
15 clearInterval(trigger);
16 }
17
18 mesh.rotation.y = ry;
19
20 render();
21
22 }, 1000);
Output
THREE.WebGLRenderer 92
WORKING AS STRING: 0.31
string
FIXED AS NUMBER: 0.31
number
WORKING AS STRING: 0.62
string
FIXED AS NUMBER: 0.62
number
WORKING AS STRING: 0.93
string
FIXED AS NUMBER: 0.9299999999999999
number
In depth talk on Mantissa/Significand:
Everything you never wanted to know about JavaScript numbers
Bartek Szopka: Only says these numbers exist, no fix, quite interesting in knowing what is happening under the hood