Skip to content

Commit beab1b2

Browse files
committed
Merge branch 'format_fixes'
2 parents 33efe51 + 0ce7c82 commit beab1b2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/roo/excelx/cell/number.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def generate_formatter(format)
4848
when /^(0+)$/ then "%0#{$1.size}d"
4949
when /^0\.(0+)$/ then "%.#{$1.size}f"
5050
when '#,##0' then number_format('%.0f')
51-
when '#,##0.00' then number_format('%.2f')
52-
when '#,##0.000' then number_format('%.3f')
51+
when /^#,##0.(0+)$/ then number_format("%.#{$1.size}f")
5352
when '0%'
5453
proc do |number|
5554
Kernel.format('%d%%', number.to_f * 100)
@@ -65,6 +64,7 @@ def generate_formatter(format)
6564
when '#,##0.00;[Red](#,##0.00)' then number_format('%.2f', '[Red](%.2f)')
6665
# FIXME: not quite sure what the format should look like in this case.
6766
when '##0.0E+0' then '%.1E'
67+
when "_-* #,##0.00\\ _€_-;\\-* #,##0.00\\ _€_-;_-* \"-\"??\\ _€_-;_-@_-" then number_format('%.2f', '-%.2f')
6868
when '@' then proc { |number| number }
6969
else
7070
raise "Unknown format: #{format.inspect}"

test/excelx/cell/test_number.rb

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def test_formats
6666
['0.000000000', '1042.000000000'],
6767
['#,##0', '1,042'],
6868
['#,##0.00', '1,042.00'],
69+
['#,##0.000', '1,042.000'],
6970
['0%', '104200%'],
7071
['0.00%', '104200.00%'],
7172
['0.00E+00', '1.04E+03'],
@@ -74,6 +75,7 @@ def test_formats
7475
['#,##0.00;(#,##0.00)', '1,042.00'],
7576
['#,##0.00;[Red](#,##0.00)', '1,042.00'],
7677
['##0.0E+0', '1.0E+03'],
78+
["_-* #,##0.00\\ _€_-;\\-* #,##0.00\\ _€_-;_-* \"-\"??\\ _€_-;_-@_-", '1,042.00'],
7779
['@', '1042']
7880
].each do |style_format, result|
7981
cell = Roo::Excelx::Cell::Number.new '1042', nil, [style_format], nil, nil, nil

0 commit comments

Comments
 (0)