Home >> PHP - MySQL PHP with example codes - 1.2 [Page 6] Article by: Shelton Manage Friday, 22nd May, 2009
About Numbers
PHP has both Intiger and Floting-Point (Decimal) number types. Valid number type variables in PHP can be anithing like.
- 8
- 3014
- 10990647985
- -4.2398503
Notice that these values are never qutoted-in which case they'd be stings with numeric values-nor do they in include commas to indicate thousands.
There are dozens of functions. I'll introduce here are round() and number_format(). The former round a decimal to either nearest intiger.
$n = 3.14; $n = round ($n); // 3
or to specific number of decimal places
$n = 30142857 $n = round ($n, 3); // 3.143
The number_format() function turns a number into the more commonly written verdion. grouped into thousands using commas. For example:
$n = 20943; $n = number_format ($n); // 20,943
This function can also a specified number of decimal points.
$n = 20943; $n = number_format ($n, 2); // 20.943.00
Page: First - 1 2 3 4 5 6 7 8 9 10 - Last
|