Surely someone has already done this and I am just a lazy searcher. But here’s something that often comes up so I made a plugin for myself, and you guys can have it too.
Imagine, you have a shopping cart with products in it. So in the template you say something like:
{exp:my_shopping_cart}
<h2>Cool Item</h2>
Only ${price} !!!11!one!!
{/exp:my_shopping_cart}
But this gets rendered as follows with no commas or decimal points :(
<h2>Cool Item</h2>
Only $12000 !!!11!one!!
So what do you do? Add PHP to that template? Noooo, you use this nifty plugin.
{exp:my_shopping_cart}
<h2>Cool Item</h2>
Only ${exp:number_format number="{price}" decimals="2"} !!!11!one!!
{/exp:my_shopping_cart}
And it renders the way you wanted it:
<h2>Cool Item</h2>
Only $12,000.00 !!!11!one!!
Basically it’s just a wrapper for PHP’s number_format function.
Hey guys, thanks for the replies. In the usage section of the plugin there are examples on how to change the thousands_seperator or the decimal_point. I didn’t choose those names, PHP did with their awesome open source coding standards, oh, wait, never mind. Please see the PHP doc for more information on how number_format works, all the parameters are named the same and are just passed through to the function. http://php.net/manual/en/function.number-format.php
Also it’s named number_format because that’s the name PHP chose. I used the shopping cart example, because I’m using it in my shopping cart.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.