{"id":20380297,"url":"https://github.com/juliaplots/numericio.jl","last_synced_at":"2025-07-15T15:36:36.998Z","repository":{"id":61798915,"uuid":"53961657","full_name":"JuliaPlots/NumericIO.jl","owner":"JuliaPlots","description":"Fine control over numeric output: Scientific/Engineering/SI-notation +UTF8","archived":false,"fork":false,"pushed_at":"2025-02-23T14:33:37.000Z","size":58,"stargazers_count":18,"open_issues_count":4,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T10:49:25.981Z","etag":null,"topics":["engineering-notation","scientific-notation","si-notation","si-prefixes","si-units"],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JuliaPlots.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-15T16:43:31.000Z","updated_at":"2025-06-23T12:30:49.000Z","dependencies_parsed_at":"2024-10-20T09:55:21.738Z","dependency_job_id":null,"html_url":"https://github.com/JuliaPlots/NumericIO.jl","commit_stats":null,"previous_names":["ma-laforge/numericio.jl"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/JuliaPlots/NumericIO.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaPlots%2FNumericIO.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaPlots%2FNumericIO.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaPlots%2FNumericIO.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaPlots%2FNumericIO.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuliaPlots","download_url":"https://codeload.github.com/JuliaPlots/NumericIO.jl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuliaPlots%2FNumericIO.jl/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265443491,"owners_count":23766408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["engineering-notation","scientific-notation","si-notation","si-prefixes","si-units"],"created_at":"2024-11-15T02:06:48.055Z","updated_at":"2025-07-15T15:36:36.950Z","avatar_url":"https://github.com/JuliaPlots.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NumericIO.jl\n\n[![Build Status](https://github.com/JuliaPlots/NumericIO.jl/workflows/CI/badge.svg)](https://github.com/JuliaPlots/NumericIO.jl/actions?query=workflow%3ACI)\n\n## Description\n\nImproved support for formatting numeric data.\n\n - Includes facilities to display values using SI prefixes (`Y`, `Z`, `E`, `P`, `T`, `G`, `M`, `k`, `m`, \u0026mu;, `n`, `p`, `f`, `a`, `z`, `y`)\n - Makes it easy to control the number of significant digits to display.\n\n## Basic Usage\n\nNumericIO.jl tries to provide the convenience of c++ `ios_base` configurability (ex: setting `ios_base::precision`) *without* modifying the output format of the base streaming object. Instead, NumericIO.jl uses the `FormattedIO` wrapper object to print data with the desired output format.  This appears to be somewhat similar (but not as flexible) as the `Base.IOContext` object used in core Julia.\n\nTo obtain a string representation of a `Real` value using SI prefixes, one can use the `formatted` function:\n\n\tformatted(3.14159e-8, :SI, ndigits=3) # =\u003e \"31.4n\"\n\nSimilarly, one can generate a string using scientific notation with the following:\n\n\tformatted(3.14159e-8, :SCI, ndigits=3) # =\u003e \"3.14×10⁻⁸\"\n\nOr using engineering notation (limiting to powers divisible by 3) with:\n\n\tformatted(3.14159e-8, :ENG, ndigits=3) # =\u003e \"31.4×10⁻⁹\"\n\nTo limit results to `ASCII` output, specify the `charset` keyword:\n\n\tformatted(3.14159e-8, :ENG, ndigits=3, charset=:ASCII) # =\u003e \"31.4E-9\"\n\nOne might also prefer to create a convenience formatting function:\n\n\tSI(x) = formatted(x, :SI, ndigits=4)\n\tSI(3.14159e-9) # =\u003e \"3.142n\"\n\tSI(2.71828e12) # =\u003e \"2.718T\"\n\nTo print out multiple values, it is preferable (more efficient) to directly create a FormattedIO wrapper object:\n\n\tfio = formatted(STDOUT, :SI, ndigits=4) # =\u003e FormattedIO\n\tprintln(fio, 3.14159e-9) # =\u003e 3.142n\n\tprintln(fio, 2.71828e12) # =\u003e 2.718T\n\t...\n\n## Advanced Usage\n\nLower-level structures of NumericIO can be used to fine-tune numeric output even further, if desired.  The following shows an example that approximates engineering notation using the `ASCII` characterset only:\n\n\tasciiexponentfmt = NumericIO.IOFormattingExpNum(\n\t\t\"x10^\", false, '+', '-', NumericIO.ASCII_SUPERSCRIPT_NUMERALS\n\t)\n\tfmt = NumericIO.IOFormattingReal(asciiexponentfmt,\n\t\tndigits=4, decpos=0, decfloating=true, eng=true, minus='-', inf=\"Inf\"\n\t)\n\tfio = formatted(STDOUT, fmt) # =\u003e FormattedIO\n\tprintln(fio, 3.14159e-8) # =\u003e 31.42x10^-9\n\nIt is also possible to generate the mantissa \u0026 exponent portions of a number separately.  This could be useful when displaying a plot's tick labels when using a common axis multiplier.  See implementation of `NumericIO.print_formatted(..., showexp=false)` and `NumericIO.print_formatted_exp(...)` for details.\n\n\u003ca name=\"Sample_Applications\"\u003e\u003c/a\u003e\n## Sample Applications\n\n### Improved REPL output (Julia console)\n\nUsers can make REPL outputs easier to read, simply by adding a few lines to their `~/.julia/config/startup.jl` file:\n\n```\nimport REPL\nusing NumericIO\n\n#Change how Float32/64s are displayed on `REPLDisplay`:\nBase.display(r::REPL.REPLDisplay, v::Union{Float32,Float64}) = print(formatted(REPL.outstream(r.repl), :SI, ndigits=4), v)\n\n#Change how `Vectors` are displayed on `REPLDisplay`:\nfunction Base.display(r::REPL.REPLDisplay, v::Vector)\n\tfio = formatted(REPL.outstream(r.repl), :SI, ndigits=4)\n\tN = length(v)\n\tprintln(REPL.outstream(r.repl), N, \"-element \", typeof(v), \":\")\n\tfor v_i in v\n\t\tprintln(fio, v_i) #Use formatted output\n\tend\nend\n```\n\nThis solution should be fairly safe: few programmers writing to REPL displays would later read back values from said display (failing the subsequent read operation).  The most likely issue with this application is that programmers expecting carefully formatted output would now have suboptimal-looking output.\n\n#### RE: Array outputs.\n\nNote that defining the above `display` method does not alter how `Array{Float}` arrays are displayed.  In order to change this particular output, one would have to define something like:\n\n```\nBase.show{T\u003c:Base.AbstractIOBuffer}(ctx::IOContext{T}, v::Union{Float32,Float64}) = print(formatted(ctx.io, :SI, ndigits=4), v)\n```\n\n... because currently (Julia v0.5.0) arrays generate their outputs by writing to temporary `IOBuffer`s.\n\n**This solution is not recommended**: it involves altering the behaviour of relatively low-level functions.  It is likely to cause issues.\n\n#### RE: Coordinating with SIUnits.\n\nAgain, the `display` function described above does not work in conjuction with SIUnits.jl - because the displayed object is of type `SIQuantity` (not `Float32/64`).  One could, instead define the following function:\n\n```\nBase.show(io::IOContext{Base.Terminals.TTYTerminal}, v::Union{Float32,Float64}) = print(formatted(io, :SI, ndigits=4), v)\n```\n\nWhich would work for formatting outputs of `SIQuantity` values, in addition to many (but not all) other values written to terminal.\n\nNote however, that `show()` is a lower level function, and this definition is more likely to cause undesired behaviours.\n\n## Known Limitations\n\n - Support for SI notation is limited between `y (1e-24)` and `Y (1e24)`.  Values beyond this range default to scientific notation.\n - SI notation displays `{1e9, 10e9, 100e9}` as `{1G, 10G, 100G}`.  It would be possible to reconfigure NumericIO to arbitrarily display `{1G, 10G, 0.1T}`, or `{1G, 0.01T, 0.1G}`, or ...\n - Algorithms are likely be a bit more complicated than absolutely necessary.  It would be nice to simplify/optimize the code as much as possible.\n - Does not support arbitrary bases (ex: `1x2^8`).\n\n### Compatibility\n\nExtensive compatibility testing of NumericIO.jl has not been performed.  The module has been tested using the following environment(s):\n\n - Windows 10 / Linux / Julia-1.7.3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaplots%2Fnumericio.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliaplots%2Fnumericio.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliaplots%2Fnumericio.jl/lists"}