PHP नंबर_फॉर्मेट () फ़ंक्शन
उदाहरण
प्रारूप संख्या:
<?php
echo number_format("1000000")."<br>";
echo number_format("1000000",2)."<br>";
echo number_format("1000000",2,",",".");
?>
परिभाषा और उपयोग
number_format () फ़ंक्शन समूहीकृत हज़ारों के साथ एक संख्या को स्वरूपित करता है।
नोट: यह फ़ंक्शन एक, दो या चार पैरामीटर (तीन नहीं) का समर्थन करता है।
वाक्य - विन्यास
number_format(number,decimals,decimalpoint,separator)
पैरामीटर मान
Parameter | Description |
---|---|
number | Required. The number to be formatted. If no other parameters are set, the number will be formatted without decimals and with comma (,) as the thousands separator. |
decimals | Optional. Specifies how many decimals. If this parameter is set, the number will be formatted with a dot (.) as decimal point |
decimalpoint | Optional. Specifies what string to use for decimal point |
separator | Optional. Specifies what string to use for thousands separator. Only the first character of separator is used. For example, "xxx" will give the same output as "x" Note: If this parameter is given, all other parameters are required as well |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | स्वरूपित संख्या लौटाता है |
---|---|
पीएचपी संस्करण: | 4+ |
चेंजलॉग: | PHP 5.4 के अनुसार, यह फ़ंक्शन दशमलव बिंदु और विभाजक पैरामीटर में एकाधिक बाइट्स का समर्थन करता है । पुराने संस्करणों में प्रत्येक विभाजक का केवल पहला बाइट इस्तेमाल किया गया था। |
और ज्यादा उदाहरण
उदाहरण
आप एक मूल्य वापस करना चाहते हैं: एक पैरामीटर संख्या को गोल करेगा (इसे दशमलव के बिना स्वरूपित किया जाएगा)। दो मापदंडों को वह परिणाम देना चाहिए जो आप चाहते हैं:
<?php
$num = 1999.9;
$formattedNum = number_format($num)."<br>";
echo $formattedNum;
$formattedNum = number_format($num, 2);
echo $formattedNum;
?>
❮ पीएचपी स्ट्रिंग संदर्भ