Skip to content

Commit 45a36e1

Browse files
committed
Fix issue #61
1 parent 3bae545 commit 45a36e1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/fmtcore.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ end
203203
function _pfmt_floate(out::IO, sch::Char, zs::Integer, u::Real, prec::Int, e::Integer, ec::Char)
204204
intv = trunc(Integer,u)
205205
decv = u - intv
206+
if intv == 0 && decv != 0
207+
intv = 1
208+
decv -= 1
209+
end
206210
_pfmt_float(out, sch, zs, intv, decv, prec)
207211
print(out, ec)
208212
if e >= 0

test/fmtspec.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ fs = FormatSpec("d")
179179
@test fmt(".1e", 0.6) == "6.0e-01"
180180
@test fmt(".1e", 0.9) == "9.0e-01"
181181

182+
# issue #61
183+
@test fmt("1.0e", 1e-21) == "1.e-21"
184+
@test fmt("1.1e", 1e-21) == "1.0e-21"
185+
182186
@test fmt("10.2e", 1.2e100) == " 1.20e+100"
183187
@test fmt("11.2e", BigFloat("1.2e1000")) == " 1.20e+1000"
184188
@test fmt("11.2e", BigFloat("1.2e-1000")) == " 1.20e-1000"

0 commit comments

Comments
 (0)