Skip to content
Advertisement

Number formatting (Money) in PHP

I’m trying to format numbers with not decimal points or commas, I’ve tried number_format() and money_format() and can’t seem to get the result I need.


number_format($item->amount,2)

Result: 14,995.00


money_format(“%i”, $item->amount)

Result: 14,995.00


I’m want to get the following numbers formatted correct.

14995 needs to be £149.95

6795 needs to be £67.95

What is the best way to get the result above?

Advertisement

Answer

Using brick/money (disclaimer: I’m the author):

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement