Solved

javascript toFixed() problem

Posted on 2013-06-11
3
496 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 500 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 82

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
jquery not working after div reload 4 38
Drop down list show all elements but disabled for selection 6 40
selected value 16 26
Problem in javascript 17 32
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

730 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