2

I'm trying to format money for Swiss locale, and my company needs it formated like this:

9'949.50

-191'565.10

But when I apply following code in JSP:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:setLocale value="de_CH" scope="session"/>
<fmt:formatNumber value="${value}" type="currency" />

I get ok money formatting but it adds currency code, which we don't want. So this is result:

SFr. 9'949.50

SFr. -191'565.10

Is there a way to turn off currency code display? I tried in various ways but all I get is exceptions.

Edit: as pointed in comments, this is JSP related question.

Community
  • 1
  • 1
Nikola Zarić
  • 865
  • 1
  • 9
  • 28
  • 1
    Possible duplicate of [Format currency without currency symbol](http://stackoverflow.com/questions/8658205/format-currency-without-currency-symbol) – BillRobertson42 Jan 19 '16 at 14:25
  • @Bill this is more of a JSP question, not really a JAVA question. So I don't think it's a duplicate. – TT. Jan 19 '16 at 15:09
  • check out. http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fmt/formatNumber.html The HaRLoFei answer below looks correct. – DwB Jan 19 '16 at 15:45

3 Answers3

6

Not sure whether it'll help or not. Can you please try add currencySymbol attribute with empty string as value? Like below:

<fmt:formatNumber value="${value}" type="currency" currencySymbol=""/>
HaRLoFei
  • 316
  • 1
  • 8
1

Best Number format in my humble opinion is big decimal format , however modern frame work such spring or Jsf has conversion formatter support see http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html using spring tag will automatically format in client side ,But for pure jsp It is best to use jsp beans:

    public class Formatter implements java.io.Serializable
{
   private String currency= null;

   public String getCurrency(){
      return [format here];
   }

   //setter
}

and in jsp use

   <jsp:useBean id="cid" class="Formatter" >
   <jsp:setProperty name="cid" property="currency"  
                    value="value"/>
   <jsp:getProperty name="cid" property="currency"/>
    ...........
   </jsp:useBean>
Ali.Mojtahed
  • 2,537
  • 1
  • 15
  • 23
0
<c:set value="20014825.50" var="val" scope="request"/>
<fmt:setLocale value="de_CH"/>
<fmt:formatNumber value="${val}" minFractionDigits="2"/>