damienoneill2001
damienoneill2001

Reputation: 499

Display trailing zero for price in jquery

Hopefully someone can help with this. I am simply looking to add the final zero to the decimal part of a price in a price calculator I am written.

The calculator starts with a user selecting a standard "Sign Up" fee of €25.50 and then selecting other packages to increase the price.

At the moment, the standard price displays as €25.5.

costs = jQuery('.cost-container').text();
total = Number(costs) + (25.50).toFixed(2);

I got this code by looking at the following similar query: How to add a trailing zero to a price with jQuery

Currently, if I enter 25.511 as my value, the result displays as 25.51, which shows that the code is sort of working, my issue is just when the second decimal place is 0 that it does not display.

Can anybody spot what is wrong?

Cheers

Damien

Upvotes: 3

Views: 1242

Answers (1)

Chris Gunawardena
Chris Gunawardena

Reputation: 6468

Try

costs = jQuery('.cost-container').text();
total = ( Number(costs) + 25.50 ).toFixed(2);

Upvotes: 1

Related Questions