JSTL Fmtformatnumber date, number, currency format

Source: Internet
Author: User
Tags locale
JSTL Fmt:formatnumber Date, number, currency format

Use <fmt> tags should be imported first

<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jsp/jstl/fmt"%>

Its URI can be under the Fmt.tld file

1. Date format

<fmt:formatdate value= "${xxx.date}" pattern= "Yyyy-mm-dd HH:mm:ss"/>

Value: Date to format

Pattern: Format of date formatting

2 Number Format

<fmt:formatnumber value= "A" type= "currency" pattern= "$.00"/>--$12.00

<fmt:formatnumber value= "A" type= "currency" pattern= "$.0#"/>--$12.0

<fmt:formatnumber value= "1234567890" type= "Currency"/>--$1,234,567,890.00 (the symbol for that currency is related to the local setting of the current Web server)

<fmt:formatnumber value= "123456.7891" pattern= "#, #00.0#"/>--123,456.79

<fmt:formatnumber value= "123456.7" pattern= "#, #00.0#"/>--123,456.7

<fmt:formatnumber value= "123456.7" pattern= "#, #00.00#"/>--123,456.70

<fmt:formatnumber value= "A" type= "percent"/>-1,200% (type can be currency, number, and percent)

1. Java formatted output:

DecimalFormat df = new DecimalFormat ("format");

String FMT =df.format (double);

Symbolic meaning

01 Digit

# one digit, leading 0 and rear-end 0 do not show

. decimal point Split position

, the location of the group separator

-Negative prefix

% with 100 multiplication and display percent sign

Any other symbol includes the specified symbol in the output string

2. Programming to achieve the internationalization of fixed text

The ResourceBundle class provides a static method getbundle that is used to mount a resource file and create a ResourceBundle instance:

Locale Currentlocale = Locale.getdefault ();

ResourceBundle MyResources =

Resourcebundle.getbundle (basename, Currentlocale);

basename is the resource packet name (and must be a full path).

The code is as follows:

<%

ResourceBundle bundler =

Resourcebundle.getbundle ("Class3g.web.properties.MyProperties",

Request.getlocale ());

%>

<form>

<%=bundler.getstring ("username")%><input type= "text" name= "username"/><br/>

<%=bundler.getstring ("password")%><input type= "text" name= "password"/><br/>

<input type= "Submit" value= "<%=bundler.getstring" ("Submit")%> "/><br/>"

</form>

<!--

<fmt:setbundle basename= "Class3g.web.properties.MyProperties"/>

-->

<fmt:bundle basename= "Class3g.web.properties.MyProperties" >

<form>

<fmt:message key= "username"/><input type= "text" name= "username"/><br/>

<fmt:message key= "password"/> <input type= "text" name= "password"/><br/>

<input type= "Submit" value= "<fmt:message key=" Submit "/>"/><br/>

</form>

</fmt:bundle>

The three manifestations of the current time are as follows:<br><br>

(1): <fmt:formatdate value= "<%=new date ()%>" type= "date"/><br><br>

(2): <fmt:formatdate value= "<%=new Date ()%>" type= "Time"/><br><br>

(3): <fmt:formatdate value= "<%=new Date ()%>" type= "both"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.