JSFiddle - React, Tailwind, and code Playground

by heera

HTML

<input id="first" value="0.5"> + <input id="second" value="0.7"> = <input id="result"><br>

The problem:<br>
Try 0.1 + 0.2, it does not equal to 0.3<br>
0.01 + 0.06 does not equal to 0.07

CSS

input{
    width:50px;
}

JavaScript

function add(){
        var first=parseFloat($("#first").val());
        var second=parseFloat($("#second").val());
        $("#result").val(+(first+second).toFixed(2));
}

add();
$("input").blur(add);

console.log(+(0.1 + 0.2).toFixed(12) );