can you explain why the number for example 0.3095 is rounded to 0.309 and not to 0.310.
If number is0.3094 rounded is 0.309 that is OK
If number is0.3096 rounded is 0.310 that is OK
The problem is when rounding 5.
I'm using calculations in datatables like:
...
{ "data": "columndata" ,
render: function(data, type, row){
return parseFloat(data/1000).toFixed(3);
} },
...
Where columndata is 309.500 before calculation.
Here is test case:
https://jsfiddle.net/to8p2hdy/
Test case of working solution:
https://jsfiddle.net/to8p2hdy/1/
Why Math.round do the trick but only parsefloat did not?
You stumbled upon the fact that some decimal numbers do not have an exact representation in the binary system. For example 0.1 can not be represented in the binary system, the closest we get is 0.1000000000000000055511151231257827021181583404541015625.
This is much like "a third" can not be represented in the decimal system because it would need to be 0.333333....
Go to https://www.exploringbinary.com/floating-point-converter/ and find that 0.3095 can not be repesented by a float but instead becomes 0.30949999999999999733546474089962430298328399658203125, which is rounded down instead of up.