DEV Community

Discussion on: Mac OS for the Web!

Collapse
 
blackr1234 profile image
blackr1234 • Edited

Yes, toFixed() is the JS way to round a Number and obtain a string. It will work if we know the number of fraction digits. If we divide numbers like 1/3, toFixed(1) will result in an answer 0.3 with a huge deviation compared to something like 0.333333.
Actually I am also looking for a good answer to this question. But I do have a workaround: to use toLocaleString with an en_US locale and maximumFractionDigits specified as 16 or less.

Thread Thread
 
mohammad_mahdi profile image
Muhammad Mahdi

That's right,
it's a great idea to use toLocaleStringwith an en_US locale and maximumFractionDigits specified as 16 or less. 👍

Some comments have been hidden by the post's author - find out more