Need a special offer?Find out if your project fits.
+

Rounding issue and data parsing

Answered
Artem asked on October 22, 2019

Hi,
I have two questions:

  1. In the dataset I'm using there is a column with floating point numbers(attached). When Grand Total is summed up for this column, it's 12102.00000000002, though it should be 12102. It looks like it's JS floating-point arithmetic issue rather than FlexMonster one, but do you plan to apply some fixes for it?
  2. Numbers in the dataset are used with dollar signs. As I understand FlexMonster did some parsing to be able to understand that this is a number, not a string. Is there any description of how it's parsed in documentation? And does it make sense(performance-wise) to parse it on my side instead of passing it this way?

Thanks in advance

4 answers

Public
Vera Didenko Vera Didenko Flexmonster October 23, 2019

Hello, Artem,
 
Thank you for writing to us.
 
Please see our answers below: 
 
1) We would like to confirm that it is a JS floating-point arithmetic issue.
Our development team will continue to research it. We will keep you updated.
 
In the meantime, we kindly suggest using the maxDecimalPlaces parameter to limit the number of digits after the floating-point. 
Please see the following JSFiddle example for illustration: https://jsfiddle.net/flexmonster/s5w2460v/
 
2) About parsing:
The result of data parsing for numbers included in quotes may differ depending on the used browser and user locale.
We strongly recommend passing raw data to Flexmonster and configuring the formatting (for example, the currency symbol) in the report object.
Please see our number formatting tutorial for guidance: https://www.flexmonster.com/doc/number-formatting/#!currency
This approach is also illustrated in the provided JSFiddle example: https://jsfiddle.net/flexmonster/s5w2460v/
 
 
Please let us know if you have any questions.
 
Best Regards, 
Vera

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster November 5, 2019

Hello, Artem,
 
We are happy to let you know that the issue with beautifying numbers with a floating point was fixed.
 
This is available in the 2.7.18 version of Flexmonster: https://www.flexmonster.com/release-notes/
 
You are welcome to update the component.
Here is our updating to the latest version guide for assistance: https://www.flexmonster.com/doc/updating-to-the-latest-version/ 
 
Please let us know if everything works fine for you.
 
Best Regards,
Illia

Public
Artem September 2, 2020

Hi Illia,
It seems like issue is not fully fixed. I managed to reproduce it again:
https://jsfiddle.net/7z9hxdv0/
Could you check?

Public
Vera Didenko Vera Didenko Flexmonster September 2, 2020

Hello, Artem,
 
Thank you for reaching out to us. 
 
We would like to kindly explain that although we have introduced several rounds of improvements, it is not possible to fully control the way floating-point numbers work. The following resource provides an explanation of why floating-point math is not accurate.
 
As a possible solution, our team recommends using the maxDecimalPlaces parameter to limit the number of possible decimal places, for instance:

formats: [
{
name: "distanceFormat",
decimalPlaces: -1,
decimalSeparator: ".",
maxDecimalPlaces: 1
}
]

Here is a modified version of the provided JSFiddle: https://jsfiddle.net/flexmonster/gzuL0845/
 
Please let us know if this helps.
 
Kind regards, 
Vera

Please login or Register to Submit Answer