Solved

javascript toFixed() problem

Posted on 2013-06-11
3
472 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now