Skip to content

Commit 15f097f

Browse files
authored
Merge pull request #50 from jmkuhn/zero
Properly format -0.0
2 parents 71a75a6 + 18604a0 commit 15f097f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/fmtcore.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ _digitchar(x::Integer, ::_Oct) = Char('0' + x)
6363
_digitchar(x::Integer, ::_Hex) = Char(x < 10 ? '0' + x : 'a' + (x - 10))
6464
_digitchar(x::Integer, ::_HEX) = Char(x < 10 ? '0' + x : 'A' + (x - 10))
6565

66-
_signchar(x::Number, s::Char) = x < 0 ? '-' :
66+
_signchar(x::Real, s::Char) = signbit(x) ? '-' :
6767
s == '+' ? '+' :
6868
s == ' ' ? ' ' : '\0'
6969

test/fmtspec.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ fs = FormatSpec("d")
111111

112112
@test fmt("", 0.125) == "0.125"
113113
@test fmt("f", 0.0) == "0.000000"
114+
@test fmt("f", -0.0) == "-0.000000"
114115
@test fmt("f", 0.001) == "0.001000"
115116
@test fmt("f", 0.125) == "0.125000"
116117
@test fmt("f", 1.0/3) == "0.333333"

0 commit comments

Comments
 (0)