Add dollar sign and commas to a number?

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?

Read More

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;

Related posts

Leave a Reply

2 comments

  1. 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, '.', ',');
    
  2. Just a guess (you really need to be more specific in your Q – what screen, how did you add it, metabox/settings section/bla???)…

    $foo = get_option( 'your_option_name' ); 
    echo '$'.$foo['bar']; // where bar is the searched value in the options array