JSTL fmt: formatNumber format the date, number, and currency of the data, and jstlformatnumber

Source: Internet
Author: User

JSTL fmt: formatNumber format the date, number, and currency of the data, and jstlformatnumber
JSTL fmt: formatNumber date, number, and currency formatting

Use the <fmt> label

<% @ Taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>

Its uri can be in the fmt. tld File

1. Date formatting

<Fmt: formatDate value = "$ {XXX. date}" pattern = "yyyy-MM-dd HH: mm: ss"/>

Value: the date to be formatted.

Pattern: Format of the date format

 

2. digit formatting

<Fmt: formatNumber value = "12" type = "currency" pattern = "$. 00"/> -- $12.00

<Fmt: formatNumber value = "12" type = "currency" pattern = "$. 0 #"/> -- $12.0

<Fmt: formatNumber value = "1234567890" type = "currency"/> -- $1,234,567,890.00 (the currency symbol 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 = "12" type = "percent"/> -- 1,200% (type can be currency, number, and percent)

 

Java formatted output:

DecimalFormat df = new DecimalFormat ("format ");

String fmt = df. format (double );

Symbolic Meaning

0: one digit

# One digit, leading zero and ending zero are not displayed

. Decimal place

, Group separator location

-Negative number prefix

% Multiply by 100 and display the percentage sign

Other symbols include the specified symbols in the output string.

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.