How can I format a price to two decimal places?

16,082

I believe you could use the code below:

$numberformatted = number_format($number, 2, '.', '');

More information: http://php.net/manual/en/function.number-format.php

Hope that helps.

Share:
16,082
Efficient Trade Ltd
Author by

Efficient Trade Ltd

Hello, I am a young New Zealand entrepreneur seeking to complete a complex trade website. Any help would be much appreciated!!

Updated on November 21, 2022

Comments

  • Efficient Trade Ltd
    Efficient Trade Ltd over 1 year

    I was having trouble displaying some prices on my website in currency format (2 decimal places). Instead the values were being displayed at 4 decimal places.

    Someone edited my original question and made it look terrible which made this post get negative rep!! :(.

    Anyways, the answer is described below. Basically insert a function to my php variable.

  • Efficient Trade Ltd
    Efficient Trade Ltd about 12 years
    Thanks man, I used as follows: $MOQ_Unit_Price_formatted = number_format($MOQ_Unit_Price, 2, '.', ''); $BPQ_Unit_Price_formatted = number_format($BPQ_Unit_Price, 2, '.', '');