zoukankan      html  css  js  c++  java
  • fmt:formatNumber use locale display negative currency in -$xxx.xx format in JSTL

    First, we want to know our own locale,how to display the locale in a JSTL?

    <c:out value="${pageContext.request.locale.language}"/> 
    


    I'm confused with the jstl tag libs:

    I want to format a number to a currency with german style

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    <html>
    <head>
        <title>format number</title>
    </head>
    <body>
        <c:set var="val" value="40.52" />
        <p> Currency in USA
        <fmt:setLocale value="en_US" scope="session"/>
    
        <fmt:formatNumber value="${val}" type="currency" />
        </p>
        <p>Currency in Germany
        <fmt:setLocale value="de_DE" scope="session"/>
    
        <fmt:formatNumber value="${val}" type="currency"/>
        </p>
    </body>
    </html>

    And thats the output:
    Currency in USA $40.52
    Currency in Germany 40,52 



    I am using fmt:formatNumber to format currency in JSTL, it will display negative currency in ($100) format, if you want to make it display negative currency in negative format instead of ($100).

    I would suggest:

    <fmt:formatNumber type="currency" pattern="$#,##0.00;-$#,##0.00" value="-10000" />

    You can remove '$' from the pattern, if you like.


    order example:

    <c:set  var="val"  value="46563746375"/>
    <fmt:formatNumber  value="${val}"  pattern="###.###E0"/>

    If you run the above code you will see the number is formatted as the pattern which is 46.5637E9 .

    关注公众号,分享干货,讨论技术




  • 相关阅读:
    关于jQuery动态多次绑定的问题及解决
    零基础英文盲打的建议
    29道Java简答题
    Redis分布式锁的实现(纯文字)
    小程序三级联动(动态获取数据)
    sql中按in中的ID进行排序输出
    layui中对表格操作按钮集的判断
    Linq改进
    C#前台直接调用后台数据时,<p>或双引号出现转义的问题
    sql 中sum函数返回null的解决方案
  • 原文地址:https://www.cnblogs.com/molashaonian/p/9097572.html
Copyright © 2011-2022 走看看