Add commas as thousands separator and floating point dot in php
问题 I have this $example = "1234567" $subtotal = number_format($example, 2, '.', ''); the return of $subtotal is "1234567.00" how to modify the definition of $subtotal, make it like this "1,234,567.00" 回答1: Below will output 1,234,567.00 $example = "1234567"; $subtotal = number_format($example, 2, '.', ','); echo $subtotal; Syntax string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' ) But I advise you to use money_format which will