當前位置: 首頁> 函數類別大全> number_format

number_format

以千位分隔符方式格式化一個數字
名稱:number_format
分類:字符串
所屬語言:php
一句話介紹:以千位分組來格式化數字。

定義和用法

number_format()函數通過千位分組來格式化數字。

註釋:該函數支持一個、兩個或四個參數(不是三個)。

實例

例子1

格式化數字:

 <?php
echo number_format ( "5000000" ) . "<br>" ;
echo number_format ( "5000000" , 2 ) . "<br>" ;
echo number_format ( "5000000" , 2 , "," , "." ) ;
?>

親自試一試

例子2

您希望返回一個價格:一個參數將對數字進行舍入(格式化為不帶小數位),兩個參數給出您想要的結果:

 <?php
$num = 4999.9 ;
$formattedNum = number_format ( $num ) . "<br>" ;
echo $formattedNum ;
$formattedNum = number_format ( $num , 2 ) ;
echo $formattedNum ;
?>

親自試一試

同類函數
  • 計算指定字符串在目標字符串中最後一次出現的位置 strrpos

    strrpos

    計算指定字符串在目標字符串中最後一次出現
  • 檢查字符串是否以給定的子字符串結尾 str_ends_with

    str_ends_with

    檢查字符串是否以給定的子字符串結尾
  • 使用一個字符串分割另一個字符串為數組 explode

    explode

    使用一個字符串分割另一個字符串為數組
  • 解碼一個uuencode 編碼的字符串 convert_uudecode

    convert_uudecode

    解碼一個uuencode編碼的字符串
  • 將邏輯順序希伯來文(logical-Hebrew)轉換為視覺順序希伯來文(visual-Hebrew),並且轉換換行符 hebrevc

    hebrevc

    將邏輯順序希伯來文(logical-He
  • 二進制安全比較字符串(從偏移位置比較指定長度) substr_compare

    substr_compare

    二進制安全比較字符串(從偏移位置比較指定
  • 反引用一個使用addcslashes() 轉義的字符串 stripcslashes

    stripcslashes

    反引用一個使用addcslashes()
  • 查找字符串的首次出現 strstr

    strstr

    查找字符串的首次出現
熱門文章