EDIT: How to get right calculation result

Tags: #<Tag:0x00007f8b1ae78db0>

Hello,
if I use in handsontable a following calculation:
1,223-1,222 I got 0.001000000000000112

example here:
https://jsfiddle.net/janzitniak/4smjoLwb/29/
(I apologize I changed that example many times to better meets my needs :slight_smile:

I would like to get right calculation result (0,001).
EDIT: I know I can change a pattern

numericFormat: {
  pattern: "0.000",
  culture: "de-DE",
}

but it rounds to 3 decimals. I need any decimal places depends on the situation.
Jan

Hi @jan.zitniak

Unfortunately, this is a known JavaScript limitation that is well explained in this article http://adripofjavascript.com/blog/drips/avoiding-problems-with-decimal-math-in-javascript.html. Plus in the Handsontable the value is also converted via Numbro.

Maybe you could add some conditional to check how many decimals places there here.

ps. if you are not sure what to use in your project we can schedule a short call to discuss the possible approaches.

1 Like

@aleksandra_budnik thank you for your quick response and explanation. Also thanks for your professional approach to help me with my project. Iโ€™ll try to manage by myself and then I can inform you.

1 Like

Hi @jan.zitniak

We havenโ€™t had an update here for a while. Did you succeed?