Solved

Javascript 2 decimals force two zeroes if needed

Posted on 2016-10-24
4
75 Views
Last Modified: 2016-10-26
I inherited the code on my html page
 $("#ctl00_ContentPlaceHolder1_txtSubscriptionCost").val((subscriptionprice).toFixed(2));

It displays the number fine but I need to force two decimals

I have tried .round(2) but it fails.... in fact nothing happens

Right now, if I have a whole number comes in it displays a 149
I need that to display as 149.00
0
Comment
Question by:lrbrister
4 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 300 total points
ID: 41857982
Is subscriptionprice a variable? Does it contain a number or a string?

If it is a variable that contains a number, try removing the extra set of parentheses around it.
$("#ctl00_ContentPlaceHolder1_txtSubscriptionCost").val(subscriptionprice.toFixed(2) );

Open in new window

0
 
LVL 7

Assisted Solution

by:Vimal DM
Vimal DM earned 200 total points
ID: 41858295
Hi,

This may help you a lot,

parseFloat(Math.round(num3 * 100) / 100).toFixed(2);

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 41861023
Thanks guys
0

Featured Post

Independent Software Vendors: 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

756 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