Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/roo/excelx/cell/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def generate_formatter(format)
def number_format(formatter, negative_formatter = nil)
proc do |number|
if negative_formatter
formatter = number.to_i > 0 ? formatter : negative_formatter
formatter = negative_formatter if number.to_f.negative?
number = number.to_f.abs
end

Expand Down
12 changes: 12 additions & 0 deletions test/excelx/cell/test_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ def test_formats_with_negative_numbers
end
end

def test_formats_with_zeros
[
['#,##0 ;(#,##0)', '0'],
['#,##0 ;[Red](#,##0)', '0'],
['#,##0.00;(#,##0.00)', '0.00'],
['#,##0.00;[Red](#,##0.00)', '0.00']
].each do |style_format, result|
cell = Roo::Excelx::Cell::Number.new '0', nil, [style_format], nil, nil, nil
assert_equal result, cell.formatted_value, "Style=#{style_format}"
end
end

def test_numbers_with_cell_errors
Roo::Excelx::ERROR_VALUES.each do |error|
cell = Roo::Excelx::Cell::Number.new error, nil, ['General'], nil, nil, nil
Expand Down