Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All numbers are read as Float #100

Open
amhofny opened this issue Aug 25, 2021 · 1 comment
Open

All numbers are read as Float #100

amhofny opened this issue Aug 25, 2021 · 1 comment

Comments

@amhofny
Copy link

amhofny commented Aug 25, 2021

When reading an excel file that is exported from other libraries, for example caxlsx https://github.com/caxlsx/caxlsx
The library generates Excel with floats and integers represented with t="n", for example from the "sheet1.xml"

<c r="Z2" s="0" t="n"><v>1.0</v></c>
<c r="G2" s="0" t="n"><v>114</v></c>

Both of these numbers are read by Creek as: 1.0 , 114.0, which is causing problems when the system expects to see an integer value instead of float, for example when using that number to load Models from the Database

I have found in this line https://github.com/pythonicrubyist/creek/blob/master/lib/creek/styles/converter.rb#L47
That Creek always read the value as float.

My suggestion is to replace

value.to_f

with

if value.to_i.to_s == value.to_s
     value.to_i
 else
     value.to_f
 end

I don't know if this is the right solution or not, but by applying this as a patch in the system solved our problem.

@bmd08a1
Copy link

bmd08a1 commented Nov 15, 2023

I think we can check for the style :fixnum or :bignum to decide whether we should use to_i or convert_bignum. Something like this:

when `n`
  case style
  when :fixnum
    value.to_i
  when :bignum
    convert_bignum(value)
  else
    value.to_f
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants