adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.65k stars 926 forks source link

Is there a way to multiply out (undo) exponential notation for floats? #779

Open petertorelli opened 1 year ago

petertorelli commented 1 year ago

Consider this:

a = 1234.56;
a.toPrecision(3);
// 1.23e+3

How do I force this back to 1230 using .format()? I know I can do it with logs/mods, etc, but I was hoping there's a way to do it with this library. I basically want it to always print significant figures, like toPrecision but without switching to exponents if the significant figures are fewer than or equal to the log10 of the value.