diff --git a/src/fmtcore.jl b/src/fmtcore.jl index e96a9af..7983a45 100644 --- a/src/fmtcore.jl +++ b/src/fmtcore.jl @@ -264,14 +264,14 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat) else rax = round(ax; sigdigits = fs.prec + 1) e = floor(Integer, log10(rax)) # exponent - u = rax * exp10(-e) # significand + u = round(rax * exp10(-e); sigdigits = fs.prec + 1) # significand i = 0 v10 = 1 while isinf(u) i += 1 i > 18 && (u = 0.0; e = 0; break) v10 *= 10 - u = v10 * rax * exp10(-e - i) + u = round(v10 * rax * exp10(-e - i); sigdigits = fs.prec + 1) end end diff --git a/test/fmtspec.jl b/test/fmtspec.jl index 2d38e50..ddf6377 100644 --- a/test/fmtspec.jl +++ b/test/fmtspec.jl @@ -150,7 +150,7 @@ end # Issue #110 (in Formatting.jl) f = FormatExpr("{:+d}") for T in (Int8, Int16, Int32, Int64, Int128) - @test format(f, typemin(T)) = string(typemin(T)) + @test format(f, typemin(T)) == string(typemin(T)) end end @@ -257,6 +257,9 @@ end @test pyfmt("+11.3e", 1.0e-309) == "+1.000e-309" @test pyfmt("+11.3e", 1.0e-313) == "+1.000e-313" + # issue #108 (from Formatting.jl) + @test pyfmt(".1e", 0.0003) == "3.0e-04" + @test pyfmt(".1e", 0.0006) == "6.0e-04" end @testset "Format special floating point value" begin @@ -279,6 +282,7 @@ end @test pyfmt("<5f", Inf) == "Inf " @test pyfmt("^5f", Inf) == " Inf " @test pyfmt(">5f", Inf) == " Inf" + @test pyfmt("*<5f", Inf) == "Inf**" @test pyfmt("⋆<5f", Inf) == "Inf⋆⋆" @test pyfmt("*^5f", Inf) == "*Inf*"