Skip to content

Commit 8fbd663

Browse files
Merge pull request #548 from magellan-ai/fix-percentage-formatted-value
Fix :formatted_value for `0%`-formatted numeric cells
2 parents 3c3eff0 + 3dfc1e1 commit 8fbd663

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/roo/excelx/cell/number.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def generate_formatter(format)
5151
when /^#,##0.(0+)$/ then number_format("%.#{$1.size}f")
5252
when '0%'
5353
proc do |number|
54-
Kernel.format('%d%%', number.to_f * 100)
54+
Kernel.format('%.0f%%', number.to_f * 100)
5555
end
5656
when '0.00%'
5757
proc do |number|

test/excelx/cell/test_number.rb

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def test_percent
3535
assert_kind_of(Float, cell.value)
3636
end
3737

38+
def test_rounded_percent_formatted_value
39+
cell = Roo::Excelx::Cell::Number.new '0.569999999995', nil, ['0%'], nil, nil, nil
40+
assert_equal('57%', cell.formatted_value)
41+
end
42+
3843
def test_formats_with_negative_numbers
3944
[
4045
['#,##0 ;(#,##0)', '(1,042)'],

0 commit comments

Comments
 (0)