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

Rounding Errors on Decimal fields #494

Open
siassaj opened this issue Nov 13, 2019 · 0 comments
Open

Rounding Errors on Decimal fields #494

siassaj opened this issue Nov 13, 2019 · 0 comments

Comments

@siassaj
Copy link

siassaj commented Nov 13, 2019

A bit of strangeness, version 2.20.0

After creating an invoice via

xeroizer_invoice = @application.Invoice.find(id)
xeroizer_invoice.line_items = []
xeroizer_invoice.attributes = attributes
xeroizer_invoice.save!

We get some strange rounding errors:

xeroizer_invoice.sub_total
=> 0.9999e2

xeroizer_invoice.attributes[:sub_total]
=> 0.1e3

xeroizer_invoice.attributes[:sub_total] == xeroizer_invoice.sub_total
=> false

This has also happenend on other fields such as total.

Briefly, in model_definition_helper I found

define_simple_attribute(field_name, :decimal, options, 0.0)

This method looks to be setting up a getter method with on transformation.

define_method internal_field_name do 
  @attributes[field_name].nil? ? value_if_nil : @attributes[field_name]
end

Any ideas what's up?

EDIT: I looked at what calculated: true is doing but it doesn't look to be the problem...

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

2 participants