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 Respostas
+ 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 è°ąè°ąđ