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
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.