Support

Account

Home Forums General Issues Thousand Separator

Solving

Thousand Separator

  • Really love your plugin, but I’m having trouble with the number field. When I enter a number into a field the number displays without a thousand separator. I’ve searched high and low for how to add one but can’t figure it out.

    My field is called “feet” and when I enter the number 2,347, it displays as 2347.

    Can you please tell me the code I need and where to put it so that the output has a thousand separator?

    Thanks.

  • To output in the desired format, just use the PHP function number_format.

    
    $feet = get_field('feet');
    echo number_format($feet, 2, '.', ',');
    
  • Thanks for responding to my question.

    I’ve tried adding the number function to custom-functions.php and when that didn’t work to functions.php, but it still doesn’t add anything to the output. The code put 0.00 in the corner of my wordpress editor page, but didn’t do anything to the field’s number. Am I adding the code to the wrong place? Do I have to put the field in the loop for it to work? Sorry, but I’m very much a novice when it comes to php.

  • Sorry to bother you again, but did I put the code in the wrong place? Is it supposed to go in functions.php?

  • I’m having the exact same problem — did you ever find a solution?

    I added the code to the functions.php file, but it returned a 0.00 in the upper left corner of the page. I’m not sure where/how to add this code so that it will format the custom field output where ever it is used on the entire site.

  • You have to add the code in your page where you want to display the output,

    example:
    <?php $output = get_field(‘on-road_price’); $price = number_format( $output, 0, ”, ‘,’); echo $price; ?></p>

    Replace ‘on-road_price’ with your field name.

  • Im also struggling to get comma separators working. I have no real experience with PHP. Im ok adding a snippet of code to the functions.php file on my child theme but can only copy and paste code there as i cant write or really understand php coding.

    Anyway, i found this snippet of code which works perfectly fine, but, i can only get it to work using a single field and i have two pricing formats on my site i need to have working.

    Can anyone tell me how to include another field name in this snippet so it still works?

    add_filter(‘acf/format_value/name=rental_price’, ‘fix_number’, 20, 3);
    function fix_number($value, $post_id, $field) {
    $value = number_format($value);
    return $value;
    }

    Ive tried, adding the other field name after rental price with a comma separating them and a space, without a space, adding additional ‘ before the next field, nothing seems to work.

    Anyone working with a single price field this snippet works just fine. Unfortunately for me i need to use on two different price fields, rental_price and capital_price

    Anyone that can help would be much appreciated.

    I see some people have kindly offered some insight how to fix but for people like me who dont understand php the answers are a little too vague.

    Thanks for your time

  • Ok, after playing around with the snippet i figured out a solution for adding this function to two fields.

    Im guessing this isnt the best way to get this done and PHP developers will probably be smiling but, i got the result i needed.

    add_filter(‘acf/format_value/name=rental_price’, ‘fix_number’, 20, 3);
    add_filter(‘acf/format_value/name=capital_price’, ‘fix_number’, 20, 3);
    function fix_number($value, $post_id, $field) {
    $value = number_format($value);
    return $value;
    }

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Thousand Separator’ is closed to new replies.