Subtraction problems with decimals in javascript [duplicate]

2

I want to do a subtraction with javascript, but I have problems subtracting with Decimal numbers for example:

Float: function () {                     var One = parseFloat (1);                     var Dos = parseFloat (0.65);                     RR var = (One - Two);                     $ ('# txtResultadoFlotacion'). val (RR);                 }

CORRECT REST

and debugging I get this:

in RR has a value of 0.35 which is correct.

INCORRECT REST:

But if I want to do a subtraction with a decimal value between the range of 0.65 to 0.99, it returns the following:

what I would expect is that RR = 0.30 HELP, please

    
asked by José MN 10.11.2016 в 07:39
source

1 answer

2

Javascript operates with floating-point numbers, which can not always store the exact value of a number . This is a common problem in many languages, not only javascript

I recommend you visit
Why can not my programs do arithmetic correctly?
where you talk in depth about the subject.

    
answered by 10.11.2016 / 08:01
source