Skip to content

Commit

Permalink
Merge pull request #548 from magellan-ai/fix-percentage-formatted-value
Browse files Browse the repository at this point in the history
Fix :formatted_value for `0%`-formatted numeric cells
  • Loading branch information
patrickkulling authored Oct 30, 2023
2 parents 3c3eff0 + 3dfc1e1 commit 8fbd663
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/roo/excelx/cell/number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def generate_formatter(format)
when /^#,##0.(0+)$/ then number_format("%.#{$1.size}f")
when '0%'
proc do |number|
Kernel.format('%d%%', number.to_f * 100)
Kernel.format('%.0f%%', number.to_f * 100)
end
when '0.00%'
proc do |number|
Expand Down
5 changes: 5 additions & 0 deletions test/excelx/cell/test_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def test_percent
assert_kind_of(Float, cell.value)
end

def test_rounded_percent_formatted_value
cell = Roo::Excelx::Cell::Number.new '0.569999999995', nil, ['0%'], nil, nil, nil
assert_equal('57%', cell.formatted_value)
end

def test_formats_with_negative_numbers
[
['#,##0 ;(#,##0)', '(1,042)'],
Expand Down

0 comments on commit 8fbd663

Please sign in to comment.