Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Justin on Aug 28, 2009 07:37
open dhtmlx forum
groupBy and totals with many decimal places

I am using the groupBy function as follows:
mygrid.groupBy(0,['#title','#cspan','','','','#stat_total','','#stat_total','#stat_total']);

The detail in the last column under one group is:
37.14
8.34

My problem is that the last '#stat_total' column generates the following number based on that detail:
45.480000000000004

What is the best way of forcing the formatting to be only two decimal digits? And is this normal behavior?... I've checked the data and the numbers in the detail rows have only two decimal places.
Answer posted by Support on Aug 28, 2009 09:51
>>And is this normal behavior?
Yes, javascript is not the best for precise calculations, its float implementation can cause such rounding errors. 

>>What is the best way of forcing the formatting to be only two decimal digits?
Define column type as edn ( ron - if it need to be readonly ) and use 
            grid.setNumberFormat("0.00",index); // index - index of column in question
grid will use formatting rules to all data in the column, including a data in the "group" row