?
Solved

javascript toFixed() problem

Posted on 2013-06-11
3
Medium Priority
?
560 Views
Last Modified: 2013-06-11
Okay this is crazy I have a form that has 3 text inputs
the first takes a quantity, the second the unit price and the third the ext price
i take the quantity and times it by the unit price and make the total the ext price value
and i format the ext price with .toFixed(2) all that is fine
however when i also try to format the unit price to 2 decimals i receive the following error

TypeError: unitprice.toFixed is not a function @ http://www.360-biz.com/www4/printquote/quote-lz-2.html:23

Can anyone please help and tell me why, i will not include the entire html just the pertinent parts



How can it be that the .toFixed() function works the first time but not the second time?
I am baffled.....
0
Comment
Question by:leozayas
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39238650
Use
var unitprice = parseInt($("#unitprice1").val());

It works the first time because it is assumed to be a number because of the calculation
0
 
LVL 83

Expert Comment

by:leakim971
ID: 39238664
replace : var unitpricex = unitprice.toFixed(2);
by : var unitpricex = (unitprice * 1).toFixed(2)
0
 

Author Closing Comment

by:leozayas
ID: 39238673
thank you gary :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question