I have a field on the admin side where a user enters a number for a price. If a user enters 1000000 I’d like to be able to display on the front-end $1,000,000.

Any ideas on how to accomplish this?

Edit
More details, the post is a custom post type ‘property’.

To add the meta fields on the back-end I’m using Meta Box Script, http://www.deluxeblogtips.com/2011/03/meta-box-script-update-v30.html

The code to display the numbers on the front-end I use

$meta = get_post_meta(get_the_ID(), 'rw_propPrice', true); echo $meta;

2 Answers
2

To format number, you can use the function number_format_i18n (it’s not documented now, but you can see its source here). Its work is format the number based on the language. You might want to look at number_format (PHP built_in function, and is used by number_format_i18n) to have more control to decimal point and thousand separator.

In your case, this code will help you:

$meta = get_post_meta(get_the_ID(), 'rw_propPrice', true);
echo '$' . number_format($meta, 0, '.', ',');

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *