2011-12-28

[PHP] number_format()

php 提供了一個 function,讓我們可以輕鬆的格式化數字

number_format

string number_format ( float $number [, int $decimals = 0 ] )
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

可以運用這個 function,
決定你的浮點數小數點後要輸出幾位($decimals),

或是,
調整你輸出的數字格式所要使用的小數點字元($dec_point),跟千位數的分隔字元($thousands_sep)

當然,不想用其中一個符號時,放個空字串('')也是可以的


Reference:
PHP: number_format

沒有留言 :

張貼留言