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

Converter int is truncating floats #554

Closed
zeycus opened this issue Aug 24, 2016 · 4 comments
Closed

Converter int is truncating floats #554

zeycus opened this issue Aug 24, 2016 · 4 comments
Milestone

Comments

@zeycus
Copy link

zeycus commented Aug 24, 2016

Excel stores numbers as float, even numbers we enter as integers. Using the converter numbers=int truncates those floats to integers, without rounding them first. The result is that if in the cell you enter a 252, you may get a 251 when you read in python using numbers=int. That happens when the internal representation of 252 is, say, 251.999999999999423579.

I think just rounding before applying int would solve this issue nicely.

@fzumstein
Copy link
Member

You got a point there. For now, what you can do is use a lambda expression to accomplish this: xw.Range('A1').options(numbers=lambda x: int(round(x))).value. Out of curiosity, what version of Excel/OS are you using (as we can't replicate the issue for 252)?

ericremoreynolds added a commit that referenced this issue Aug 24, 2016
@fzumstein fzumstein added this to the v0.9.4 milestone Aug 24, 2016
@zeycus
Copy link
Author

zeycus commented Aug 24, 2016

It's Windows 8.1 Enterprise, with Microsoft Office Enterprise 2007 version 12.0.6612.1000

In the meantime I'll use what you suggested, thanks.

@ericremoreynolds
Copy link
Contributor

Hi @zeycus,

The default behavior has now been changed on the develop branch, so using numbers=int will round the float before applying the int constructor. The rare (nonexistent?) cases where one doesn't want this behavior, one can specify numbers='raw int' and the int constructor will be applied without rounding.

Regards,

Eric

@zeycus
Copy link
Author

zeycus commented Aug 24, 2016

Hi @eric,

Agree with the solution, that was awfully quick!

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