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

float precision problem #11

Closed
SKoschnicke opened this issue Sep 11, 2012 · 4 comments
Closed

float precision problem #11

SKoschnicke opened this issue Sep 11, 2012 · 4 comments

Comments

@SKoschnicke
Copy link

I created a test case where "-1912.167" is read as "-1912.1670000000001" from an excel file. I think it results from some floating point conversions but can't find the code which creates floats from an excel file. Maybe someone else knows the place.

Here is the test case:
SKoschnicke/spreadsheet-1@f309aeb

@zdavatz
Copy link
Owner

zdavatz commented Dec 1, 2012

I guess it is Ruby that does that.

@zdavatz zdavatz closed this as completed Dec 1, 2012
@EtienneDepaulis
Copy link

Hey guys,
we have the exact same problem. Any idea on how to fix it ?
Cheers

@SKoschnicke
Copy link
Author

Here is a hack you may use:

  def self.fix_spreadsheet_float(number_string)
    if /\.\d*000000[123456789]$/.match number_string
      Rails.logger.info "removing last digit of #{number_string} because it seems to be a float precision problem"
      return number_string.chop
    else
      return number_string
    end
  end

@zdavatz
Copy link
Owner

zdavatz commented Dec 5, 2014

Thanks for sharing this!

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

No branches or pull requests

3 participants