Wrong value after multiplication by 100

javascript

Solution

Because of the non-exact nature of floating point values (this is not JavaScript's fault), you need to be more specific, i.e.:

$('p.price').text(function (i, v) {
    return (v * 100).toFixed(10);
});

Where `.toFixed(10)` determines the desired size of your fraction.

Problem

The jQuery displays 12.123456789123003 instead of 12.123456789123 when this value 1212.3456789123 multiplies with 100. Code: ``` <p class="price">12.123456789123</p> <button>Calculate</button> $(':button').click(function () { $('p.price').text(function (i, v) { return v * 100; }); this.disabled = true; }); ```

Original source

Related problems