php number_format函數怎麼用?
number_format函數是PHP中的內建函數,用於格式化一個包含數千個分組的數字,其語法是「string number_format ( $number, $decimals, $decimalpoint, $sep )」。
這篇文章主要跟大家介紹php number_format用法,希望對需要的朋友有幫助!
number_format()函數是PHP中的內建函數,用來格式化一個包含數千個分組的數字。它在成功時會傳回格式化的數字,否則在失敗時給出E_WARNING
。
語法:
string number_format ( $number, $decimals, $decimalpoint, $sep )
參數:
此函數接受上述四個參數,如下所述:
$number
:它是指定要格式化的數字的必要參數。如果沒有設定其他參數,則該數字將被格式化為不含小數,並使用逗號(,)作為千位分隔符號。必須參數指定要格式化的數字。
$decimals
:它是可選參數,用來指定小數。如果設定了此參數,則該數字將使用圓點(.)作為小數點進行格式化。
$decimalpoint
:它是一個可選參數,用來指定要用於小數點的字串。
$sep
:它是可選參數,用於指定用於千位分隔符號的字串。如果給定了該參數,則需要所有其他參數。
傳回值:
成功時傳回格式化的數字,失敗時傳回E_WARNING。
number_format()程式碼範例1:
<?php $num1 = "999999.49"; // 没有小数点参数 echo number_format($num1)."\n"; // 带小数点参数 echo number_format($num1, 3)."\n"; $num2 = "9999999.99"; // 没有小数点参数 //返回整数值 echo number_format($num2)."\n"; //带小数点参数 echo number_format($num2, 3)."\n"; // 包含所有四个参数 echo number_format("1000000.99", 3, "#", "GGG"); ?>
#輸出:
999,999 999,999.490 10,000,000 9,999,999.990 1GGG000GGG000#990
number_format()程式碼範例2:
如果傳遞任何東西而不是數字,它則會給予警告。
<?php $num = "GFG"; echo number_format($num)."\n\n"; echo number_format($num, 3); ?>
#輸出:
PHP Warning: number_format() expects parameter 1 to be float, string given in /home/ac476aaecea758334cb8ed146bcbb8f6.php on line 5 PHP Warning: number_format() expects parameter 1 to be float, string given in /home/ac476aaecea758334cb8ed146bcbb8f6.php on line 8
number_format()程式碼範例3:
此函數不接受三個參數,只接受1、 2或4個參數。
<?php $num = 1000000; echo number_format($num, 3, ", "); ?>
輸出:
PHP Warning: Wrong parameter count for number_format() in /home/e426108b066d9a86366249bf7b626d19.php on line 6
相關推薦:《PHP教學》
以上是php number_format函數怎麼用?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undress AI Tool
免費脫衣圖片

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

testthepdfinanotherapptoderineiftheissueiswiththefileoredge.2.enablethebuilt inpdfviewerbyTurningOff“ eflblyopenpenpenpenpenpdffilesexternally”和“ downloadpdffiles” inedgesettings.3.clearbrowsingdatainclorwearbrowsingdataincludingcookiesandcachedcachedfileresteroresoreloresorelorsolesoresolesoresolvereresoreorsolvereresoreolversorelesoresolvererverenn

VSCode中可通過快捷鍵快速切換面板與編輯區。要跳轉至左側資源管理器面板,使用Ctrl Shift E(Windows/Linux)或Cmd Shift E(Mac);返回編輯區可用Ctrl `或Esc或Ctrl 1~9。相比鼠標操作,鍵盤快捷鍵更高效且不打斷編碼節奏。其他技巧包括:Ctrl KCtrl E聚焦搜索框,F2重命名文件,Delete刪除文件,Enter打開文件,方向鍵展開/收起文件夾。

runthewindowsupdatetrubloubleshooterviaSettings>更新&安全> is esseShootsoAtomationfixCommonissues.2.ResetWindowSupDateComponentsByStoppingRealatedServices,RenamingTheSoftWaredWaredWaredSoftwaredSistribution andCatroot2Folders,intrestrestartingthertingthertingtherserviceSteStoceTocle

Useinterfacestodefinecontractsforunrelatedclasses,ensuringtheyimplementspecificmethods;2.Useabstractclassestosharecommonlogicamongrelatedclasseswhileenforcinginheritance;3.Usetraitstoreuseutilitycodeacrossunrelatedclasseswithoutinheritance,promotingD

phparrayshandledatAcollectionsefefityIndexedorassociativuctures; hearecreatedWithArray()或[],訪問decessedviakeys,modifybyAssignment,iteratifybyAssign,iteratedwithforeach,andManipulationUsfunsionsFunctionsLikeCountLikeCountLikeCountLikeCountLikecount()

breakexitstheloopimmediatelyafterfindingatarget,idealforstoppingatthefirstmatch.2.continueskipsthecurrentiteration,usefulforfilteringitemsliketemporaryfiles.3.gotojumpstoalabeledstatement,acceptableinrarecaseslikecleanuporerrorhandlingbutshouldbeused

Restartyourrouterandcomputertoresolvetemporaryglitches.2.RuntheNetworkTroubleshooterviathesystemtraytoautomaticallyfixcommonissues.3.RenewtheIPaddressusingCommandPromptasadministratorbyrunningipconfig/release,ipconfig/renew,netshwinsockreset,andnetsh

TheObserverdesignpatternenablesautomaticnotificationofdependentobjectswhenasubject'sstatechanges.1)Itdefinesaone-to-manydependencybetweenobjects;2)Thesubjectmaintainsalistofobserversandnotifiesthemviaacommoninterface;3)Observersimplementanupdatemetho
