Memory App
Programming
 




Character

ord() - Return ASCII value of character

echo ord("A"); // 65
chr() - Return character by ASCII code

echo chr(65); // A
(1/4)

Number

number_format() - is not locale-aware

echo number_format("100000.698"); // 100,001

// returns a rounded number

echo number_format("100000.698", 3, ",", " "); // 100 000,698
(2/4)

Pad

str_pad() - Pad a string to a certain length with another string
    
echo str_pad("100", 6, "0"); // 100000

echo str_pad("333", 6, "0", STR_PAD_LEFT); // 000333
(3/4)

Money

money_format() It is locale-aware. Not available on Windows, as well as on some variants of UNIX

setlocale(LC_MONETARY, "en_US");
echo money_format('%.2n', "100000.698"); // $100,000.70

setlocale(LC_MONETARY, "ro_RO");
echo money_format('%.2n', "100000.698"); // Lei 100.000,70
If we change our formatting to use the i conversion character, money_format() will produce its output using the international notation.

setlocale(LC_MONETARY, "en_US");
echo money_format('%.2i', "100000.698"); // USD 100,000.70
In addition, you should keep in mind that the default rounding rules change from locale to locale. For example, US currency values are regularly expressed as dollars and cents, while Japanese currency values are represented as integers.

setlocale(LC_MONETARY, "en_US");
echo money_format('%i', "100000.698"); // USD 100,000.70

setlocale(LC_MONETARY, "ja_JA");
echo money_format('%i', "100000.698"); // JPY 100,001


Questions



Top Reference > Programming
0/0 (80)  
Not Logged