JSP/Servlet – JSTL <fmt:formatNumber> 커스텀 액션 사용하기
<fmt:formatNumber> 커스텀 액션을 사용하면 숫자를 다양한 표기 하는 것이 가능합니다.
<fmt:formatNumber value="1000" groupingUsed="true"/>
groupingUsed를 사용하면 1000을 1,000으로 표기합니다.
<fmt:formatNumber value="1.23456" pattern="#.##" />
#를 사용해서 유효숫자를 정의할 수 있습니다. 그래서1.23으로 표시됩니다.
<fmt:formatNumber value="1.2" pattern="#.00"/>
0를 사용하면 유효숫자가 없으면 0으로 채워집니다. 그래서 1.20으로 표시됩니다.
<fmt:formatNumber value="0.3" type="percent" />
type애트리뷰트를 추가하고 percent를 쓴다면 주어진 값에 100을 곱하고 %를 붙인 값이 출력됩니다.
<fmt:formatNumber value="100000" type="currency" currencySymbol="$"/>
type애트리뷰트를 추가하고 currency를 쓴다면 주어진 값을 화폐단위로 표시합니다. currencySymbol은 화폐단위 맨앞에 기호를 지정합니다.
실제로 formatNumber가 적용이 잘되는 지 확인해봅시다.
NumberFormat.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
첫 번째 : <fmt:formatNumber value="1000" groupingUsed="true"/> <BR>
두 번째 : <fmt:formatNumber value="1.23456" pattern="#.##"/> <BR>
세 번째 : <fmt:formatNumber value="1.2" pattern="#.00"/> <BR>
네 번째 : <fmt:formatNumber value="0.3" type="percent"/> <BR>
다섯번째 : <fmt:formatNumber value="100000" type="currency" currencySymbol="$"/> <BR>
</body>
</html>
실행 화면
formatNumber에서 지정한 대로 출력이 잘 되네요
'프로그래밍 > JSP Servlet' 카테고리의 다른 글
JSP/Servlet – JSTL <fmt:requestEncoding> 커스텀 액션 사용하기 (0) | 2016.02.10 |
---|---|
JSP/Servlet – JSTL 프로퍼티 파일에 변수 포함하기 (0) | 2016.02.10 |
JSP/Servlet – JSTL <fmt:setBundle>과 <fmt:bundle> <fmt:message> 커스텀 액션 사용하기 (0) | 2016.02.03 |
JSP/Servlet – JSTL <fmt:setLocale> 커스텀 액션 사용하기 (0) | 2016.02.01 |
JSTL/Servlet – JSTL <fmt:formatDate> 커스텀 액션 사용하기 (0) | 2016.01.31 |
JSP/Servlet – JSTL <c:out> 커스텀 액션 사용하기 (0) | 2016.01.31 |
JSP/Servlet – JSTL <c:url> 커스텀 액션 사용 하기 (1) | 2016.01.30 |
JSTL/Servlet – JSTL <c:redirect> 커스텀 액션 사용하기 (0) | 2016.01.30 |