I'm trying to format a number in a table cell with comma separators between thousands. The number is coming from a custom field generated in Advanced Custom Fields plugin, where it is required to be a number.
(But I've also tried just entering the number directly in the below examples.)
I'm getting the correct number value, but the formatting isn't working. Plus, I get different results from number_format inside a table cell and outside one.
My number is 429000, retrieved by the_field('price').
Here's what I've tried inside the cell:
<td class="pl-property-price"><?php number_format( the_field('price')); ?> </td>
<td class="pl-property-price"><?php number_format((int) the_field('price')); ?> </td>
<td class="pl-property-price"><?php number_format( intval(the_field('price'))); ?> </td>
<td class="pl-property-price"><?php number_format( the_field('price'), 0, ".", ","); ?> </td>
and some other variations.
No matter what I do, it outputs 429000 without the comma separator.
Now, if I try to echo the value outside the table, using code like this and all the similar variations to the above using
<?php echo number_format(the_field('price')); ?>
I get 4290000 which adds an extra zero.
I'm puzzled.