Engineering notation differs from scientific notation in that:
The exponent is always a multiple of 3, and
The digits to the left of the decimal point are scaled to range from 1 to 999.
My use case calls for specifying 0 to 13 digits to the right of the decimal point. The default is 4.
const Avogadro = 6.022140857e23
str = eng_notation(Avogadro, digits=0)
# str = "602E+21"
str = eng_notation(Avogadro, digits=1)
# str = "602.2E+21"
# Default 4 digits to right of decimal point.
str = eng_notation(Avogadro)
# str = "602.2141E+21"
str = eng_notation(Avogadro, digits=10)
# str = "602.2140857000E+21"
# Negative and fractional numbers should also work.
str = eng_notation(-0.01234567, digits=7)
# str = "-12.4567000E-03"
Any suggestions?
Use the NumericIO.jl
package
julia> using NumericIO
julia> const Avogadro = 6.022140857e23;
julia> formatted(Avogadro, :ENG, ndigits=4, charset=:ASCII)
"602.2E21"
julia> formatted(Avogadro, :ENG, ndigits=4)
"602.2×10²¹"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With