<g:formatNumber number="${120544}" format="###,##0" /> <g:formatNumber number="${557181.49}" format="###,##0" /> <g:formatNumber number="${557181.61}" format="###,##0" /> <g:formatNumber number="${120544.48}" format="###,##0.##" /> <g:formatNumber number="${0.1524}" format="%0.##" />
Below are the rendered result for the <g:formatNumber> tag's output:
120,544 557,181 557,182 120,544.48 %15.24
<g:formatNumber number="${12}" type="number" minIntegerDigits="5" /> <g:formatNumber number="${15.05}" type="number" maxFractionDigits="4" /> <g:formatNumber number="${23.22}" type="number" minIntegerDigits="5" maxFractionDigits="4" />Here is the expected rendered output:
00,012 15.05 00,023.22
<g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="CEILING" /> <g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="DOWN" /> <g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="FLOOR" /> <g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="HALF_DOWN" /> <g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="HALF_EVEN" /> <g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="HALF_UP" /> <g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="UNNECESSARY" /> <g:formatNumber number="${23.455}" type="number" maxFractionDigits="2" roundingMode="UP" />Here is the explanation from Oracle's javadoc:
We may also format a number based on currency. Here are some example usage in <g:formatNumber> :
<g:formatNumber number="${125500.12}" type="currency" currencyCode="USD" /> <g:formatNumber number="${82553.22}" type="currency" currencyCode="EUR" />
Here is the output of the code above:
$125,500.12 EUR82,553.22Available currency codes are based on ISO 4217 standard. Here are the other codes copied from Wikipedia:
Code | Country |
---|---|
AED | United Arab Emirates |
AFN | Afghanistan |
ALL | Albania |
AMD | Armenia |
ANG | Curaçao (CW), Sint Maarten (SX) |
AOA | Angola |
ARS | Argentina |
AUD | Australia, Christmas Island (CX), Cocos (Keeling) Islands (CC), Heard Island and McDonald Islands (HM), Kiribati (KI), Nauru (NR), Norfolk Island (NF), Tuvalu (TV), Australian Antarctic Territory |
AWG | Aruba |
AZN | Azerbaijan |
BAM | Bosnia and Herzegovina |
BBD | Barbados |
BDT | Bangladesh |
BGN | Bulgaria |
BHD | Bahrain |
BIF | Burundi |
BMD | Bermuda |
BND | Brunei, auxiliary in Singapore (SG) |
BOB | Bolivia |
BOV | Bolivia |
BRL | Brazil |
BSD | Bahamas |
BTN | Bhutan |
BWP | Botswana |
BYR | Belarus |
BZD | Belize |
CAD | Canada |
CDF | Democratic Republic of the Congo |
CHE | Switzerland |
CHF | Switzerland, Liechtenstein (LI) |
CHW | Switzerland |
CLF | Chile |
CLP | Chile |
CNY | China |
COP | Colombia |
COU | Colombia |
CRC | Costa Rica |
CUC | Cuba |
CUP | Cuba |
CVE | Cape Verde |
CZK | Czech Republic |
DJF | Djibouti |
DKK | Denmark, Faroe Islands (FO), Greenland (GL) |
DOP | Dominican Republic |
DZD | Algeria |
EGP | Egypt, auxiliary in Gaza Strip |
ERN | Eritrea |
ETB | Ethiopia |
EUR | Akrotiri and Dhekelia, Andorra (AD), Austria (AT), Belgium (BE), Cyprus (CY), Estonia (EE), Finland (FI), France (FR), Germany (DE), Greece (GR), Guadeloupe (GP), Ireland (IE), Italy (IT), Kosovo, Latvia (LV), Lithuania (LT), Luxembourg (LU), Malta (MT), Martinique (MQ), Mayotte (YT), Monaco (MC), Montenegro (ME), Netherlands (NL), Portugal (PT), Réunion (RE), Saint Barthélemy (BL), Saint Pierre and Miquelon (PM), San Marino (SM), Slovakia (SK), Slovenia (SI), Spain (ES), Vatican City (VA); see Eurozone |
FJD | Fiji |
FKP | Falkland Islands (pegged to GBP 1:1) |
GBP | United Kingdom, the Isle of Man (IM, see Manx pound), Jersey (JE, see Jersey pound), Guernsey (GG, see Guernsey pound), South Georgia and the South Sandwich Islands (GS), British Indian Ocean Territory (IO) (also uses USD), Tristan da Cunha (SH-TA), and British Antarctic Territory |
GEL | Georgia (except Abkhazia (GE-AB) and South Ossetia) |
GHS | Ghana |
GIP | Gibraltar (pegged to GBP 1:1) |
GMD | Gambia |
GNF | Guinea |
GTQ | Guatemala |
GYD | Guyana |
HKD | Hong Kong, Macao (MO) |
HNL | Honduras |
HRK | Croatia |
HTG | Haiti |
HUF | Hungary |
IDR | Indonesia |
ILS | Israel, State of Palestine (PS)[8] |
INR | India, Bhutan, Nepal , Zimbabwe |
IQD | Iraq |
IRR | Iran |
ISK | Iceland |
JMD | Jamaica |
JOD | Jordan, auxiliary in West Bank |
JPY | Japan |
KES | Kenya |
KGS | Kyrgyzstan |
KHR | Cambodia |
KMF | Comoros |
KPW | North Korea |
KRW | South Korea |
KWD | Kuwait |
KYD | Cayman Islands |
KZT | Kazakhstan |
LAK | Laos |
LBP | Lebanon |
LKR | Sri Lanka |
LRD | Liberia |
LSL | Lesotho |
LYD | Libya |
MAD | Morocco |
MDL | Moldova (except Transnistria) |
MGA | Madagascar |
MKD | Macedonia |
MMK | Myanmar |
MNT | Mongolia |
MOP | Macao |
MRO | Mauritania |
MUR | Mauritius |
MVR | Maldives |
MWK | Malawi |
MXN | Mexico |
MXV | Mexico |
MYR | Malaysia |
MZN | Mozambique |
NAD | Namibia |
NGN | Nigeria |
NIO | Nicaragua |
NOK | Norway, Svalbard and Jan Mayen (SJ), Bouvet Island (BV), Queen Maud Land, Peter I Island |
NPR | Nepal |
NZD | New Zealand, Cook Islands (CK), Niue (NU), Pitcairn Islands (PN; see also Pitcairn Islands dollar), Tokelau (TK), Ross Dependency |
OMR | Oman |
PAB | Panama |
PEN | Peru |
PGK | Papua New Guinea |
PHP | Philippines |
PKR | Pakistan |
PLN | Poland |
PYG | Paraguay |
QAR | Qatar |
RON | Romania |
RSD | Serbia |
RUB | Russia, Abkhazia (GE-AB), South Ossetia, Crimea |
RWF | Rwanda |
SAR | Saudi Arabia |
SBD | Solomon Islands |
SCR | Seychelles |
SDG | Sudan |
SEK | Sweden |
SGD | Singapore, auxiliary in Brunei (BN) |
SHP | Saint Helena (SH-SH), Ascension Island (SH-AC) (pegged to GBP 1:1) |
SLL | Sierra Leone |
SOS | Somalia (except Somaliland) |
SRD | Suriname |
SSP | South Sudan |
STD | São Tomé and Príncipe |
SYP | Syria |
SZL | Swaziland |
THB | Thailand , Cambodia , Myanmar , Laos |
TJS | Tajikistan |
TMT | Turkmenistan |
TND | Tunisia |
TOP | Tonga |
TRY | Turkey , Northern Cyprus |
TTD | Trinidad and Tobago |
TWD | Taiwan |
TZS | Tanzania |
UAH | Ukraine |
UGX | Uganda |
USD | United States, American Samoa (AS), Barbados (BB) (as well as Barbados Dollar), Bermuda (BM) (as well as Bermudian Dollar), British Indian Ocean Territory (IO) (also uses GBP), British Virgin Islands (VG), Caribbean Netherlands (BQ - Bonaire, Sint Eustatius and Saba), Ecuador (EC), El Salvador (SV), Guam (GU), Haiti (HT), Marshall Islands (MH), Federated States of Micronesia (FM), Northern Mariana Islands (MP), Palau (PW), Panama (PA), Puerto Rico (PR), Timor-Leste (TL), Turks and Caicos Islands (TC), U.S. Virgin Islands (VI), Zimbabwe (ZW), |
USN | United States |
USS | United States |
UYI | Uruguay |
UYU | Uruguay |
UZS | Uzbekistan |
VEF | Venezuela |
VND | Vietnam |
VUV | Vanuatu |
WST | Samoa |
XAF | Cameroon (CM), Central African Republic (CF), Republic of the Congo (CG), Chad (TD), Equatorial Guinea (GQ), Gabon (GA) |
XAG | |
XAU | |
XBA | |
XBB | |
XBC | |
XBD | |
XCD | Anguilla (AI), Antigua and Barbuda (AG), Dominica (DM), Grenada (GD), Montserrat (MS), Saint Kitts and Nevis (KN), Saint Lucia (LC), Saint Vincent and the Grenadines (VC) |
XDR | International Monetary Fund |
XFU | International Union of Railways |
XOF | Benin (BJ), Burkina Faso (BF), Côte d'Ivoire (CI), Guinea-Bissau (GW), Mali (ML), Niger (NE), Senegal (SN), Togo (TG) |
XPD | |
XPF | French territories of the Pacific Ocean: French Polynesia (PF), New Caledonia (NC), Wallis and Futuna (WF) |
XPT | |
XSU | Unified System for Regional Compensation (SUCRE)[11] |
XTS | |
XUA | African Development Bank[12] |
XXX | |
YER | Yemen |
ZAR | South Africa |
ZMW | Zambia |