Skip to content

Commit 9ad7ab2

Browse files
committed
Fix rounding before exponent for "g/G"
1 parent 267dc28 commit 9ad7ab2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/fmtcore.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ end
333333

334334
function _pfmt_g(out::IO, fs::FormatSpec, x::AbstractFloat)
335335
# Branch according to the exponent
336-
expnt = x == 0 ? 0 : floor(Int, log10(abs(x)) )
336+
ax = round(abs(x) ;sigdigits=fs.prec)
337+
expnt = ax == 0 ? 0 : floor(Int, log10(ax) )
337338
if -4 <= expnt < fs.prec
338339
newprec = fs.prec - expnt - 1
339340
_pfmt_f(out, FormatSpec(fs ;prec=newprec), x)

0 commit comments

Comments
 (0)