일반적으로 데이터베이스에 금액을 입력할 때 ,를 제외한 숫자 (int)만 insert한다.
하지만, 사용자에게 보여지는 화면에 , 기호가 없다면 가독성이 떨어진다.
이런 경우 사용자에게 보여지는 view 화면에서 기호 , 를 넣는 2가지 방법이다.
1. DecimalFormat
<<%=money> <br>
String product_money=request.getParameter("product_money");
int m = Integer.parseInt(product_money);
DecimalFormat dc=new DecimalFormat("###,###");
String money = dc.format(m);
2. toLoaleString
<span id="m"></span> <br>
<script type="module">
var money=<%=product_money%>;
document.getElementById("m").innerText=money.toLocaleString();
사용자에게 보여지는 view화면에 span id를 사용해서 적용한다.
728x90
'JAVA > JSP' 카테고리의 다른 글
프로젝트 Servlet , Server, JSP 정보와 버전 확인하기 (0) | 2023.07.04 |
---|---|
JSP로만 만든 웹페이지 index.html (메인페이지)설정하는 법 (0) | 2023.06.08 |
onkeyup, onkeydown, onkeypress, onmouseover (0) | 2022.09.05 |
CKEDITOR 초간단 추가하기/ 게시판 글쓰기 에디터 (0) | 2022.09.02 |
DB, update하기 jsp,java mvc버전 (0) | 2022.08.30 |
댓글