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.
Yes,
toFixed()is the JS way to round aNumberand obtain a string. It will work if we know the number of fraction digits. If we divide numbers like1/3,toFixed(1)will result in an answer0.3with a huge deviation compared to something like0.333333.Actually I am also looking for a good answer to this question. But I do have a workaround: to use
toLocaleStringwith anen_USlocale andmaximumFractionDigitsspecified as16or less.That's right,
it's a great idea to use
toLocaleStringwith anen_USlocale andmaximumFractionDigitsspecified as16or less. 👍