JAVA
[JSTL]fmt:formatNumber
EnzyCut
2017. 11. 22. 22:52
<fmt:formatNumber>사용법
formatNumber는 숫자, 퍼센트, 돈단위를 작성할 때 사용한다.
formatNumber을 이용하여 숫자 단위마다 콤마 자동 찍기
formatNumber의 속성 중 type에 값을 number로 하면 3자리마다 콤마가 설정된다.type의 속성 값에 할당 할 수 있는 값은 number, percentage, currency가 있다.
예제
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>formatNumber</title> </head> <body> <h3>단위마다 콤마 찍기</h3> <c:set var = "money" value = "25000" /> <p>\<fmt:formatNumber value = "${money}" type = "number"/></p> </body> </html>
formatNumber을 이용하여 통화 단위로 표현하기
type속성에 currency를 사용하면 돈 단위와 액수를 표현할 수 있다.
예제
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>formatNumber</title> </head> <body> <h3>한화로 표현하기</h3> <c:set var = "money" value = "25000" /> <p><fmt:formatNumber value = "${money}" type = "currency" currencySymbol = "\"/></p> <h3>US 달러로 표현하기</h3> <fmt:setLocale value = "en_US"/> <p><fmt:formatNumber value = "${money}" type = "currency"/></p> </body> </html>
위의 결과 값을 보면
첫번째 한화로 표현현 값은
\25,000.00
두번째 US달러로 표현한 값은
$25,000.00
으로 표현된다.
currency 는 소수점 두째자리까지 표현된다.