Support

Account

Home Forums General Issues Insert Commas into ACF number field Reply To: Insert Commas into ACF number field

  • Works beautifully! Thank you so much!

    Oddly enough the only thing I was even able to get working at the template level is the below. Kept returning either 0 or “expecting integer, received string” error. Regardless, your fix did the trick globally. Much appreciated.

    // Different versions of a number
    $unformatted = get_field('paid_attendance');
    {
        $integerValue = str_replace(",", "", $unformatted);  // Remove commas from string
        $integerValue = intval($integerValue);               // Convert from string to integer
        $integerValue = number_format($integerValue);        // Apply number format
    
        $floatValue = str_replace(",", "", $unformatted);    // Remove commas from string
        $floatValue = floatval($floatValue);                 // Convert from string to float
        $floatValue = number_format($floatValue, 2);         // Apply number format
    
        echo $integerValue;                                 // Output values
    }