Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,16 @@ function writecell(buf, pos, len, io, x::AbstractFloat, opts)
bytes = codeunits(string(x))
sz = sizeof(bytes)
@check sz
for i = 1:sz
@inbounds buf[pos] = bytes[i]
pos += 1
if opts.decimal != UInt8('.')
for i = 1:sz
@inbounds buf[pos] = bytes[i] == UInt8('.') ? opts.decimal : bytes[i]
pos += 1
end
else
for i = 1:sz
@inbounds buf[pos] = bytes[i]
pos += 1
end
end
return pos
end
Expand Down
10 changes: 10 additions & 0 deletions test/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct StructType
aumber::Union{Real, Nothing}
end

struct AF <: AbstractFloat
f::Float64
end
Base.string(x::AF) = string(x.f)

@testset "CSV.write" begin

Expand Down Expand Up @@ -156,6 +160,12 @@ end
(delim='\t', decimal=','),
"col1\tcol2\tcol3\n1,1\t4\t7\n2,2\t5\t8\n3,3\t6\t9\n"
),
# custom abstract float decimal: #1108
(
(col1=AF.([1.1,2.2,3.3]), col2=[4,5,6], col3=[7,8,9]),
(delim='\t', decimal=','),
"col1\tcol2\tcol3\n1,1\t4\t7\n2,2\t5\t8\n3,3\t6\t9\n"
),
# issue 515
(
(col1=[""],),
Expand Down