JuliaIO / Formatting.jl

Deprecated. See README. (A Julia package to provide Python-like formatting support)
Other
130 stars 23 forks source link

Add a significant-figure option for format #18

Open dpsanders opened 8 years ago

dpsanders commented 8 years ago

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 commented 8 years ago

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

dpsanders commented 8 years ago
julia> @printf("%.6g", pi)
3.14159
julia> @printf("%.6g", 10pi)
31.4159
tpapp commented 7 years ago

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 commented 7 years ago

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 commented 4 years ago

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