-1

I'm not getting the correct value if i add 2 decimal values in java script, if i add 19.67 and 34.70 i should get 54.37 instead i'm getting the value 54.370000000000005. Can anyone help me out, Thank you. below is my code

<script type="text/javascript">
    $(document).ready(function () {
        $('#btn').click(function () {
            var a = 19.67;
            var b = 34.70;
            var c = parseFloat(a) + parseFloat(b);
            alert(c);
        });
    });
</script>

1 Answers1

0

Hope this helps...

$('#btn').click(function() {
  var a = 19.67;
  var b = 34.70;
  var c = parseFloat(a+b).toFixed(2);
  alert(c);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btn">Click</button>
O.O
  • 1,389
  • 14
  • 29