Skip to content

Commit

Permalink
Merge pull request JuliaLang#14377 from sarvjeetsinghghotra/issue-14291
Browse files Browse the repository at this point in the history
RFC: Modified writedlm() to write leading zeros when writing floats JuliaLang#14291
  • Loading branch information
jakebolewski committed Dec 17, 2015
2 parents b490f74 + 4fd69c4 commit 00589c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/grisu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Base.showcompact(io::IO, x::Float16) = _show(io, x, PRECISION, 5, false)

# normal:
# 0 < pt < len ####.#### len+1
# pt <= 0 .000######## len-pt+1
# pt <= 0 0.000######## len-pt+1
# len <= pt (dot) ########000. pt+1
# len <= pt (no dot) ########000 pt
# exponential:
Expand All @@ -149,8 +149,8 @@ function _print_shortest(io::IO, x::AbstractFloat, dot::Bool, mode, n::Int)
write(io, dec(e))
return
elseif pt <= 0
# => .000########
write(io, '.')
# => 0.000########
write(io, "0.")
while pt < 0
write(io, '0')
pt += 1
Expand Down
12 changes: 12 additions & 0 deletions test/datafmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ let x = [1,2,3], y = [4,5,6], io = IOBuffer()
@test readcsv(io) == [x y]
end

let x = [0.1 0.3 0.5], io = IOBuffer()
writedlm(io, x, ", ")
seek(io, 0)
@test readall(io) == "0.1, 0.3, 0.5\n"
end

let x = [0.1 0.3 0.5], io = IOBuffer()
writedlm(io, x, ", ")
seek(io, 0)
@test readcsv(io) == [0.1 0.3 0.5]
end

let x = ["abc", "def\"ghi", "jk\nl"], y = [1, ",", "\"quoted\""], io = IOBuffer()
writedlm(io, zip(x,y), ',')
seek(io, 0)
Expand Down

0 comments on commit 00589c8

Please sign in to comment.