Solved

Javascript 2 decimals force two zeroes if needed

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

Accepted Solution

by:
Kim Walker earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks guys
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

763 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

9 Experts available now in Live!

Get 1:1 Help Now