-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to set REPL output format to engineering notation #46267
Comments
Julia Base has already the dictionary type IOContext to configure how functions like show display values. And you can already use So I guess what is missing is in IOContext support for a bit more control over the format used for floating-point numbers. At the moment there is already:
But that single Boolean parameter obviously offers fewer options than MATLAB's format command. In the form of an extended IOContext docstring, what would a nice suitable interface for the desired functionality look like? |
See also previous discussion: #6493 |
@mgkuhn thank you for the response, I will drop a quick mention to #6493 as well. An API related to what you suggest sounds very viable. Off the top of my head, I would suggest mimicing
The I would also like to make the suggestion that there is also a function or macro added that allows a more terse way of configuring this, and the other IO context options. The current version is a bit lengthy and doesn't validate the given arguments against valid values in the dictionary (I could imagine this may be desired in some cases though) # This does not complain
julia> Base.active_repl.options.iocontext[:nothing] = true;
# Could something like this be possible? It would complain here
julia> set_iocontext(compact=true, nothing=true) Also - you might already be aware but just to clarify, Julia's |
Hello all,
I would like to suggest adding a simple way to configure the output format to use engineering notation - that is, scientific notation that is restricted to powers of three. This sort of formatting is very useful for easy conversion to SI units.
For example, after enabling this feature, something like the following would be expected:
With this formatting, the outputs are quick to read as 1.2k, 10M, 100µ, etc.
The package
NumericIO
(link here) implements this functionality via functions, and this StackOverflow question includes a solution. However, both options come with overhead (a package or a lengthy function), and requires putting the output through a separate function, rather than native display (though this could likely be changed by overridingBase.show
, which is another step).Matlab/Octave allows this with
format short eng
(link to the relevant MatLab docs here).A bonus feature would be some way to do something like
format compact
to not add new lines between interpreter entries (though there may be a way to do this that I just haven't found).A bonus bonus feature would be a way to enable SI prefixes natively, like in
NumericIO
. So typing e.g.1.5k
expands to1500.0
, or2e-8
displays as20n
. (I realize that this is likely out of the scope of what the REPL intends to do, but it is an extremely helpful feature when working with science/engineering documentation)The text was updated successfully, but these errors were encountered: