How to manipulate a float value which starts from .somevalue to 0.somevalue in javascript/jquery? -
i have text box user enters numbers in float data type . value added previous value . when user adds float number 0.123
added fine when adds .123
throws error nan . using following code.
var labor_cost = number($("#labor_cost").val()); var other_cost = number($("#other_cost").val()); var profitvalue = number($("#profitvalue").val()); var ingcost = number($("#producttotalcost").val()); profitamount = ((ingcost+other_cost+labor_cost)*profitvalue/100); $("#showproposedprice").html((ingcost+other_cost+labor_cost+number(profitamount)).tofixed(2)); $("#proposedprice").val((ingcost+other_cost+labor_cost+number(profitamount)).tofixed(4));
please me how can skip or manipulate float number .123
0.123
? thanks.
update: have tried code, , cannot reproduce error. here have done (including html), updated fiddle. can reproduce error in fiddle? if so, let me know putting in each text box. if not, compare code , see what's different:
<p>labour cost: <input type="text" id="labor_cost" /></p> <p>other cost: <input type="text" id="other_cost" /></p> <p>profit value: <input type="text" id="profitvalue" /></p> <p>product total cost: <input type="text" id="producttotalcost" /></p> <button id="submit">click</button> <hr/> <p>show proposed price: <span id="showproposedprice"></span></p> <p>proposed price: <input type="text" id="proposedprice" /></p> <script type="text/javascript"> $("#submit").click(function() { var labor_cost = number($("#labor_cost").val()); var other_cost = number($("#other_cost").val()); var profitvalue = number($("#profitvalue").val()); var ingcost = number($("#producttotalcost").val()); var profitamount = ((ingcost+other_cost+labor_cost)*profitvalue/100); $("#showproposedprice").html((ingcost+other_cost+labor_cost+number(profitamount)).tofixed(2)); $("#proposedprice").val((ingcost+other_cost+labor_cost+number(profitamount)).tofixed(4)); }) </script>
Comments
Post a Comment