Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript 2 decimals force two zeroes if needed

Posted on 2016-10-24
4
Medium Priority
?
89 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
[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
4 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 1200 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 800 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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)

705 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