Hi

I have a script which displays a price but currently is not fixed to 2 decimal places so a price such as $2.50 shows as $2.5 which to me looks wrong.

The line of code is

amount += parseFloat($(this).metadata().amount);

Looking around I see there is a function

toFixed()

but I am not sure how to combine it with the above.

Any help much appreciated.

Thanks
Mark

Recommended Answers

All 3 Replies

If I am not wrong, toFixed() must be custom javascript function which fills zero to float number with one position. You can pass the current value within that function and assign to variable as new value. Like

amount += parseFloat($(this).metadata().amount);
amount = toFixed(amount);

Thank you - all sorted now.

Thanks
Mark

amount += parseFloat($(this).metadata().amount);

I think, the true solution is a:

amount += parseFloat($(this).metadata().amount).toFixed(2);

This makes sure you get: [2.50] kind of values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.