# jQuery Math Decimal Points

I have a jQuery function that adds up a total.  The issue is, if the number  has 2 decimal points and the last number is 0, it does not show the Zero.  For eample if the number is 9.30  it only shows 9.3.  How do I force it to show the Zero?

Here is part of my function, I hope it helps.

``````// START TAXES
if( state_a == 'WA') {
tax = .0011;
} else if ( state_a == 'NJ' ) {
tax = .009;
} else if ( state_a == 'WV' ) {
tax = .0055;
} else {
tax = 0;
}

var sub_p_t = parseFloat(final_premium_total) * parseFloat(tax);

var round_sub_p_t = Math.ceil(sub_p_t * 100) / 100;

var pre_tot = parseFloat(final_premium_total) + parseFloat(sub_p_t);

if( state_a == 'WA') {
premium_total = Math.ceil(pre_tot * 100) / 100;
\$('[name="item_options[0][surcharge]"]').val( round_sub_p_t );
\$(".tax-display").html('(<strong>Tax Included</strong><span class="sale_price pull-right"><span class="cart_total">\$ '+ round_sub_p_t +'</span></span>)');
} else if( state_a == 'WV') {
premium_total = Math.ceil(pre_tot * 100) / 100;
\$('[name="item_options[0][surcharge]"]').val( round_sub_p_t );
\$(".tax-display").html( '(<strong>Tax Included</strong><span class="sale_price pull-right"><span class="cart_total">\$ '+ round_sub_p_t +'</span></span>)');
} else if( state_a == 'NJ') {
premium_total = Math.ceil(pre_tot * 100) / 100;
\$('[name="item_options[0][surcharge]"]').val( round_sub_p_t );
\$(".tax-display").html( '(<strong>Tax Included</strong><span class="sale_price pull-right"><span class="cart_total">\$ '+ round_sub_p_t +'</span></span>)');
} else {
}
//  END TAXES
``````
LVL 8
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
just call toFixed(2);

``````// START TAXES
if( state_a == 'WA') {
tax = .0011;
} else if ( state_a == 'NJ' ) {
tax = .009;
} else if ( state_a == 'WV' ) {
tax = .0055;
} else {
tax = 0;
}

var sub_p_t = parseFloat(final_premium_total) * parseFloat(tax);

var round_sub_p_t = Math.ceil(sub_p_t * 100) / 100;

var pre_tot = parseFloat(final_premium_total) + parseFloat(sub_p_t);

if( state_a == 'WA') {
premium_total = Math.ceil(pre_tot * 100) / 100;
\$('[name="item_options[0][surcharge]"]').val( round_sub_p_t );
\$(".tax-display").html('(<strong>Tax Included</strong><span class="sale_price pull-right"><span class="cart_total">\$ '+ round_sub_p_t +'</span></span>)');
} else if( state_a == 'WV') {
premium_total = Math.ceil(pre_tot * 100) / 100;
\$('[name="item_options[0][surcharge]"]').val( round_sub_p_t );
\$(".tax-display").html( '(<strong>Tax Included</strong><span class="sale_price pull-right"><span class="cart_total">\$ '+ round_sub_p_t +'</span></span>)');
} else if( state_a == 'NJ') {
premium_total = Math.ceil(pre_tot * 100) / 100;
\$('[name="item_options[0][surcharge]"]').val( round_sub_p_t );
\$(".tax-display").html( '(<strong>Tax Included</strong><span class="sale_price pull-right"><span class="cart_total">\$ '+ round_sub_p_t +'</span></span>)');
} else {
}

//  END TAXES
``````
http://www.w3schools.com/jsref/jsref_tofixed.asp

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
If you're fine rounding to two decimal places, you can use toFixed. For example,
``````premium_total = final_premium_total.toFixed(2)
``````
This will also convert the value to a string. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed for more information.
Commented:
Looks like hielo beat me to submitting. :)
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.