Problem with mathamatical calculation in JQUERY

Posted by Param-Ganak on Stack Overflow See other posts from Stack Overflow or by Param-Ganak
Published on 2010-04-09T12:08:45Z Indexed on 2010/04/09 12:13 UTC
Read the original article Hit count: 182

Filed under:

Hello friends!

I have two text boxes. I enter number in one textbox. I write following JQUERY for that textbox which get executed when the focus out from first text box. The JQUERY code takes the entered value from first text box and multiply it by a decimal number 34.95 and display the answer in second text box.

The code is doing the calculation little bit ok because

when I enter the value 1000 in first text box it gives answer 34950 in second textbox and when I enter the value 100 in first text box it gives answer 3495.0000000000005 in second text box.

**Please any one tell me what is the problem. is problem is in my JQUERY code.

I also want to show the answer always in decimal point. Answer should always dislply only two digits after decimal point. so How to achieve this too.**

This is my JQUERY code.

$("#id_pvalue").focusout(function() {

                    q=$("#id_pvalue").val();

                    var ans=q*34.95;

                    $("#id_tvalue").val(ans);


            });

Please guide me friends!

Thank You!

© Stack Overflow or respective owner

Related posts about jQuery