+ 2

when we getting square root of 2 I use toFixed(3) but in this way sqrt(25)=5.000 /remove extra zeros. suggest improvements....

https://code.sololearn.com/WPfOrY86m5xu/?ref=app

25th Nov 2018, 7:23 AM
Sheraz Tariq
Sheraz Tariq - avatar
3 odpowiedzi
+ 2
A trick I like is to use parseFloat/Number/+ in combination with toFixed: parseFloat(Math.sqrt(i).toFixed(3)) OR, Number(Math.sqrt(i).toFixed(3)) OR, +(Math.sqrt(i).toFixed(3))
25th Nov 2018, 8:08 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
thanks it works
25th Nov 2018, 8:16 AM
Sheraz Tariq
Sheraz Tariq - avatar
+ 1
Glad I could help 😊
25th Nov 2018, 8:18 AM
Kishalaya Saha
Kishalaya Saha - avatar