1 Java[ | ]
Java
Copy
System.out.print( String.format("%.2f", 5.1234) ); // 5.12
System.out.print( String.format("%.2f", 5.99999) ); // 6.00
System.out.print( String.format("%.2f", 5.0) ); // 5.00
System.out.print( String.format("%.2f", (float)5) ); // 5.00
System.out.print( String.format("%.2f", 1000.1234) ); // 1000.12
2 JavaScript[ | ]

JavaScript
Copy
console.log( (5.1234).toFixed(2) ); // 5.12
console.log( (5.9999).toFixed(2) ); // 6.00
console.log( (5).toFixed(2) ); // 5.00
console.log( (1000.1234).toFixed(2) ); // 1000.12
JavaScript
Copy
var num = 2/3;
console.log( 100*num.toFixed(1) ); // 70
console.log( (100*num).toFixed(1) ); // 66.7
3 PHP[ | ]

PHP
Copy
echo number_format(5.1234, 2); # 5.12
echo number_format(5.9999, 2); # 6.00
echo number_format(5, 2); # 5.00
echo number_format(1000.1234, 2); # 1,000.12
echo number_format(1000.1234, 2, '.', ''); # 1000.12
4 Python[ | ]

Python
Copy
print( '{:0.0f}'.format(12.34) ) # 12
print( '{:0.2f}'.format(12.34) ) # 12.34
print( '{:0.4f}'.format(12.34) ) # 12.3400
print( '%0.0f' % 12.34 ) # 12
print( '%0.2f' % 12.34 ) # 12.34
print( '%0.4f' % 12.34 ) # 12.3400
5 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.
리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― Jmnote리눅스 Python 2.7 컴파일 설치 ― ㅇㅇㅇ미운코딩새끼 ― 승호 도령미운코딩새끼 ― 불탄고등어미운코딩새끼 ― 김레이미운코딩새끼 ― 호박이미운코딩새끼 ― Junhg0211미운코딩새끼 ― 김왼손미운코딩새끼 ― 용딘이미운코딩새끼 ―Pinkcrimson
유기농냠냠파이썬 ― 호박유기농냠냠파이썬 ― 이에스유기농냠냠파이썬 ― 이승현파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong