Today I went through a strange problem, a simple calculation of the sum of the difference according to the ordering.
If in the browser console perform this calculation below:
2.3+2.3+2.1
The expected value would be 6.7 correct? Yeah, but from 6.699999999999999, so far so good, it's understandable ....
But .. if I change the order of the values, putting the lower one first.
2.1+2.3+2.3
Surprise "mothafoca"! 6.7
Note: I can not use toFixed because I do not want to lease this number, where you can correct a problem now, but it will result in something worse up front.
A fucking solution that went through my head but I refuse to use it would be.
soma = 0;
[2.3, 2.3, 2.1].sort().forEach( valor => {
soma += valor
});