Formatting.jl icon indicating copy to clipboard operation
Formatting.jl copied to clipboard

Add a significant-figure option for format

Open dpsanders opened this issue 8 years ago • 5 comments

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 avatar Apr 28 '16 12:04 dpsanders

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

dpsanders avatar Apr 28 '16 12:04 dpsanders

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

dpsanders avatar Apr 28 '16 12:04 dpsanders

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.

tpapp avatar Feb 20 '17 16:02 tpapp

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.

tlnagy avatar Apr 17 '17 00:04 tlnagy

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

cossio avatar May 30 '20 00:05 cossio