PHP learning experience

My personal learning experience on php. Basic php scripting language for beginners

Wednesday, March 29, 2006

PHP Learning - Working with Data(2)

Use build-in function for simple math calculations:
To compute a square root: $number=sqrt(91);
Round up to the next interger $number=ceil(27.63);
There are a lot of function help you with calculations, I will not list them here

Usually, you will want to control how to display the number, then the statement number_format comes into play.
number_format(number,decimals,"decimalsep","thousandsep)
number is the number to be formatted. This must always be included.

decimals
is the number of decimal places. If decimals is not included,
the number of decimal places is 0 by default.

decimalsep is the character used to separate the decimal places. The
default is a decimal point. If you include this, you must also include
thousandsep.

thousandsep is the character used to separate the number into thousands.
The default is a comma. If you include this parameter, you must
also include decimalsep.

For more complicated formatting, you can use the statement "printf" and "sprintf".

0 Comments:

Post a Comment

<< Home