[PHP] 數學數字格式函數彙整 – Numeric Format Functions – (小數點.etc)

number_format() 千分位數值格式

數字格式化,千位分組,支援小數點。

echo number_format(1000.123, 2) = //1,000.12
echo number_format(1000.123, 2, '.', ''); //1000.12
echo number_format(1000.123, 2, ',', ''); //1000,12

sprintf 格式化數字

sprintf("%05d", 25); //Output: 00025

整數進位

round() //四捨五入,支援小數位數
ceil()  //無條件進入
floor() //無條件捨去

Leave a Reply

Your email address will not be published. Required fields are marked *