Skip to content
Browse files

properly recognize exponential values as float

  • Loading branch information...
1 parent df26c0c commit ddc35f6629de2b1363b0d947b4a115344be4c0d1 @randym committed Sep 7, 2012
Showing with 7 additions and 2 deletions.
  1. +2 −0 .gitignore
  2. +2 −0 README.md
  3. +1 −1 lib/axlsx/workbook/worksheet/cell.rb
  4. +2 −1 test/workbook/worksheet/tc_cell.rb
View
2 .gitignore
@@ -10,3 +10,5 @@ example.csv
*.*~
.DS_Store
tmp
+*.pem
+*.pfx
View
2 README.md
@@ -146,6 +146,8 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
#Change log
---------
- **September.??.12**: 1.2.3
+ - fix exponential float/bigdecimal values rendering as strings intead
+ of 'numbers' in excel.
- added support for :none option on chart axis labels
- added support for paper_size option on worksheet.page_setup
- **August.27.12**: 1.2.2
View
2 lib/axlsx/workbook/worksheet/cell.rb
@@ -380,7 +380,7 @@ def cell_type_from_value(v)
:boolean
elsif v.to_s.match(/\A[+-]?\d+?\Z/) #numeric
:integer
- elsif v.to_s.match(/\A[+-]?\d+\.\d+?\Z/) #float
+ elsif v.to_s.match(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/) #float
:float
else
:string
View
3 test/workbook/worksheet/tc_cell.rb
@@ -60,7 +60,7 @@ def test_type
assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
assert_nothing_raised("type can be changed") { @c.type = :string }
assert_equal(@c.value, "1.0", "changing type casts the value")
-
+ assert_equal(:float, @row.add_cell(1.0/10**7).type, 'properly identify exponential floats as float type')
assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date')
assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean')
@@ -88,6 +88,7 @@ def test_cell_type_from_value
assert_equal(@c.send(:cell_type_from_value, -1), :integer)
assert_equal(@c.send(:cell_type_from_value, true), :boolean)
assert_equal(@c.send(:cell_type_from_value, false), :boolean)
+ assert_equal(@c.send(:cell_type_from_value, 1.0/10**6), :float)
end
def test_cast_value

0 comments on commit ddc35f6

Please sign in to comment.
Something went wrong with that request. Please try again.