0

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

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by Troy III
0

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);
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.