Javascript 2 decimals force two zeroes if needed

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
Larry Bristersr. DeveloperAsked:
Who is Participating?
 
Kim WalkerWeb Programmer/TechnicianCommented:
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
 
Vimal DMSenior Software EngineerCommented:
Hi,

This may help you a lot,

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

Open in new window

0
 
Larry Bristersr. DeveloperAuthor Commented:
Thanks guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.