number_format函數(shù)是用來格式化數(shù)字的函數(shù),它可以將一個(gè)數(shù)字格式化為帶有千位分隔符、小數(shù)點(diǎn)和小數(shù)位數(shù)的字符串。
函數(shù)的語(yǔ)法是:number_format(number, decimals, decimalpoint, separator)
參數(shù)說明:
示例代碼:
$number = 12345.6789;
$formatted_number = number_format($number); // 默認(rèn)格式化為12346
$formatted_number = number_format($number, 2); // 格式化為12345.68
$formatted_number = number_format($number, 2, ",", "."); // 格式化為12,345.68
注意:number_format函數(shù)會(huì)對(duì)傳入的參數(shù)進(jìn)行四舍五入操作。