0
About toFixed() in JS
I met with a challenge question like this: let sum = 0.1 + 0.2; console.log(+sum.toFixed(2)); The answer is 0.3. Why? I thought it should be 0.30. - Confused Boy
2 Answers
+ 3
Typecasted back into Number due to the plus operator before sum.
https://code.sololearn.com/W8ZgKlTH97cJ/?ref=app
ęäøåčŖŖę³ļ¼
å¦ęåŖę sum.toFixed(2)ļ¼ēµęęÆ 0.30ļ¼å ēŗęÆStringć
ä½ē¾åØę ļ¼čåØåé¢ļ¼éå ļ¼čå ēŗåę¹ē”Stringļ¼čå¾ę¹åÆä»„parseFloat()ļ¼ę仄被å¤å®ēŗ Number.prototype.addition() ļ¼čäøęÆString.prototype.concantentation()ćå ę¤ 0.30被č½ååNumberļ¼čå°ęøé»äŗä½ē0äøęÆ significant figureļ¼ę仄åØéēØäøč¢«ęØå»äŗć
0
Gordon 谢谢š