PHP 字符串 number_format()函數
PHP字符串’number_format()’是內置的PHP函數。愛掏網 - it200.com它用于格式化具有分組千位數的數字。愛掏網 - it200.com它支持一個、兩個或三個參數(不是三個)。愛掏網 - it200.com
number_format(number,decimals,decimalpoint,separator)
參數 | 描述 | 必填/可選 |
---|---|---|
number | 正在格式化的數字。愛掏網 - it200.com | 必填 |
decimal | 設置小數點位數。愛掏網 - it200.com | 可選 |
decimalpoint | 設置小數點分隔符。愛掏網 - it200.com | 可選 |
separator | 設置千位分隔符。愛掏網 - it200.com | 可選 |
示例1
<?php
n=199.9;
echo "Your number is:".n;
echo "<br>"."By using 'number_format()' function :".number_format($n);
?>
輸出:
Your number is:199.9
By using 'number_format()' function :200
示例2
<?php
n=199.9;
echo "Your number is:".n;
echo "<br>"."By using 'number_format()' function :".number_format($n,2);
?>
輸出:
Your number is:199.9
By using 'number_format()' function :199.90
示例3
<?php
n=1000000;
echo "Your number is:".n;
echo "<br>"."By using 'number_format()' function :".number_format($n);
?>
輸出結果:
Your number is:1000000
By using 'number_format()' function :1,000,000
示例4
<?php
n=1000000;
echo "Your number is:".n;
echo "<br>"."By using 'number_format()' function :".number_format($n,2);
?>
輸出:
Your number is:1000000
By using 'number_format()' function :1,000,000.00
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。