17
When creating an order calculation system (quantity x value) I realized that in some cases when adding broken values Javascript returns numbers with many other decimal places more than expected.
Example:
(123*1.23)+(312*3.26) //retorna 1168.4099999999999 ao invés de 1168.41
Is this a common behavior in Javascript? The fact that I am calculating values with only two decimal places should not limit the result also to only two houses? Is there any way to make the behavior return the expected value (eg.: 1168.41
)?
Here the function does not round... because it will?
– Diêgo Correia de Andrade
@Diêgocorreiadeandrade my example works? if you don’t make a video or image to be able to see the error?
– Sergio