Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Add a significant-figure option for format #18

Open
dpsanders opened this issue Apr 28, 2016 · 5 comments
Open

Add a significant-figure option for format #18

dpsanders opened this issue Apr 28, 2016 · 5 comments

Comments

@dpsanders
Copy link

I have just discovered the format function, exactly what I was looking for, thanks!

Currently I can only find a precision option that fixes the number of decimal places.
It would be very useful to have a significant option that fixes the number of significant figures instead.

E.g.

julia> format(float(π), precision=5)
"3.14159"

julia> format(10*float(π), precision=5)
"31.41593"

I would like an option to fix significant=6 to get 3.14159 in the first case, and 31.4159 in the second.

@dpsanders
Copy link
Author

Oh, is this the non-implemented g option? I seem to remember that that was implemented in Julia's @printf at some point?

@dpsanders
Copy link
Author

julia> @printf("%.6g", pi)
3.14159
julia> @printf("%.6g", 10pi)
31.4159

@tpapp
Copy link

tpapp commented Feb 20, 2017

But since the * is not supported in @printf strings, one cannot determine the number of significant digits at runtime (except with the eval trick), so @printf is not a replacement for significant=x.

@tlnagy
Copy link

tlnagy commented Apr 17, 2017

It would be a great to have this feature. I had this problem with displaying pvalues where I would like to show 4 significant figures over several orders of magnitude.

@cossio
Copy link

cossio commented May 30, 2020

Is this issue still an issue? There is no longer a format function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants