반응형

money_format() 을 쓰려다가 number_format() 있길래 사용함.


number_format

(PHP 4, PHP 5)

number_format — 천의 단위로 숫자를 포맷팅한다.

Description ¶

string number_format ( float $number [, int $decimals = 0 ] )
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

이 함수는 1개나 2개 또는 4개의 파라미터만 사용한다.(3개 안됨):

한 파라미터만 주어진다면, number (첫번째 param)  decimals(2번째 param) 없이 포맷팅 될 것임, 여튼 천 단위별로 콤마(,)가 찍힐거다.

두 개의 파라미터가 주어진다면, number 는 decimals dot (".") 으로 구분되는 소숫점을 가진, 천의 단위로 콤마를 가질 것이다.

4개의 파라미터가 주어진다면, number will be formatted with decimals decimals, dec_point instead of a dot (".") before the decimals andthousands_sep instead of a comma (",") between every group of thousands.

Parameters ¶

number

The number being formatted.

decimals

Sets the number of decimal points.

dec_point

Sets the separator for the decimal point.

thousands_sep

Sets the thousands separator.

그래서 ... 확인해보니 number_format($number, '0', '.', ','); 랑 number($number) 가 기본 숫자 사용 시에는 같은 결과를 나타냈다.

반응형

+ Recent posts