본문 바로가기

프로그래밍언어/php

php (금액) 숫자 세자리 단위로 콤마,쉼표(,) 넣기

세자리 숫자 단위로 콤마(,)넣기

 

 

number_format(숫자): 세자리마다 콤마가 삽입

 

number_format(숫자, 소수점 이하 자리수): 세자리마다 쉼표가 찍히고, 소수점 이하 몇자리까지 출력할것인지 지정

 // 정수에, 천자리 마다 쉼표 넣기   
echo number_format(1234567890) # 1,234,567,890   
echo number_format(123456789)  # 123,456,789   
echo number_format(12345678)    # 12,345,678   
echo number_format(1000)       # 1,000   
echo number_format(66)         # 66       
// 천자리 쉼표 넣기 + 실수 소수점 이하 2자리까지 출력   
// 반올림이 됨   
echo number_format(1234567890.555555, 2)  # 1,234,567,890.56   
echo number_format(123456789.555555, 2) # 123,456,789.56   
echo number_format(12345678.555555, 2)   # 12,345,678.56   
echo number_format(1000.555555, 2)       # 1,000.56   
echo number_format(66.555555, 2)