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
Solved

Javascript 2 decimals force two zeroes if needed

Posted on 2016-10-24
4
70 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

839 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