Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript toFixed() problem

Posted on 2013-06-11
3
Medium Priority
?
535 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

636 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