ANN: Human-friendly numeric output (NumericIO)


#1

NumericIO provides fine control over numeric output: Scientific/Engineering/SI-notation +UTF8:

  • Includes facilities to display values using SI prefixes (Y, Z, E, P, T, G, M, k, m, μ, n, p, f, a, z, y)
  • Makes it easy to control the number of significant digits to output - as opposed to number of decimal places (similar, but not the same).
  • Link: https://github.com/ma-laforge/NumericIO.jl

Basic Usage

Create a convenience formatting function:

using NumericIO
SI(x) = formatted(x, :SI, ndigits=4)

Then use said function:

SI(3.14159e-9) # => "3.142n"
SI(2.71828e12) # => "2.718T"

For a more traditional scientific output, use the following:

formatted(3.14159e-8, :SCI, ndigits=3) # => "3.14×10⁻⁸"

Or instead restrict the output to engineering notation (limiting to powers divisible by 3):

formatted(3.14159e-8, :ENG, ndigits=3) # => "31.4×10⁻⁹"

NOTE:* I personally find numeric output easier to read in engineering notation as opposed to scientific notation.

More Advanced Usage

Fix the output to a certain floating point position:

fmt = NumericIO.IOFormattingReal(:SI, NumericIO.Charset{:UTF8}, ndigits=4, decpos=-12, decfloating=false)
SI(x) = formatted(x, fmt)

#Sample output:
SI(3.14159e-11) # => "31.42p"
SI(2.71828e-7) # => "271800p"

For more examples of advanced usage, consult the README.md page: https://github.com/ma-laforge/NumericIO.jl.

Note that the low level functions operate on IO streams, and make use of Julia’s built-in GRISU algorithms.