Javascript to format number as currency -
i have following code.
<select id="cage_options"> <option>please select</option> <option value="2,63330">option1</option> <option value="3,13300">option2</option> <option value="4,2000.00">option3</option> </select> <input id="cage_labor_estimate" disabled> <script> function format(n) { return n.tofixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); } document.getelementbyid("cage_options").addeventlistener("change", cageoptionfunction); function cageoptionfunction() { select=document.getelementbyid('cage_options').value.split(','); cage_option = select[1]; document.getelementbyid("cage_labor_estimate").value = format(cage_option); } </script>
i trying format output in disabled input box in current format following error:
typeerror: n.tofixed not function. (in 'n.tofixed(2)', 'n.tofixed' undefined)
can help?
thanks,
john
you have string , string not have .tofixed(). need convert string number.
cage_option = number(select[1]);
or
cage_option = parsefloat(select[1]);
Comments
Post a Comment