Price format Display

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 21, 2014   (RSS)

By claire - November 19, 2014

Hey Andy

You can use the same function with some extra parameters to get a different format, like so:

<?php echo number_format($listing['price'], 2, ',', '.');) ?>

This will format a number with 2 places after the decimal and a comma as the decimal separator and a period as the thousands separator, like this: 150.000,00

Here's the function reference if you want to play around with it: http://php.net/manual/en/function.number-format.php

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By andybarn - November 21, 2014

Hi Claire

Thanks for your reply, but when I pasted your code in I was getting a syntax error.

I removed the code marked in red below

<?php echo number_format($listing['price'], 2, ',', '.');) ?>

So I then had

<?php echo number_format($listing['price'], 2, ',', '.') ?>

and this worked as you indicated with 2 places after the decimal and a comma as the decimal separator and a period as the thousands separator, like this: 150.000,00

However I do not want the decimal places, I just want this to be displayed as 150.000

I therefore changed the code to

<?php echo number_format($listing['price'], 0, ',', '.') ?>

This seems to work great - can you see any problems with what I have done?

Thanks for your help Claire

Kind regards

Andy

By claire - November 21, 2014

No, that looks fine. Sorry about the syntax error!

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/