Java and freemaker keep two decimal places

1、 Java retains 2 decimal places

2、 Freemaker keeps two decimal places

Supplement: freemaker keeps decimals

Freemaker keeps two decimal places

Method 1

#{number; m1m2} m minimum and M maximum decimals

Method 2

${x?string("0.##")}

It's easy to ignore this point in development. If you enter a value (possibly a decimal), it's easy to appear if you don't deal with it in output

Invisible bug. For example, if you take a value of 0.22 from the database and generally output ${x? If_exists? HTML}, 0 is displayed instead of 0.22.

It should be written as ${x? If_exists? String. Number} or ${x? If_exists. Tostring()? HTML}

1. The number less than 1 is subtracted in freemaker

Numbers such as 210002000 are incorrectly formatted in freemaker and will be interpreted as 1000

Solution: set the display format of number in freemaker

XML code

The point is this number_ Format

Online say let number_ Format = "0", which can only solve the second case.

4、 Local settings

characteristic:

If the number format used on a page or several pages (other pages can be imported), the number format can be configured uniformly

Usage:

Just set before using the number to be formatted. The format is as follows: < #setting number_ Format = ", ##0. ##" > the content of ", ##0. ##" adopts a syntax similar to the number format in Java, that is, the third point above.

be careful:

If it is used on a page, the whole page defaults to that format, unless the default format is overwritten with the string function. Similarly, if it is placed on a public page, other pages will have the same format as long as they include it.

5、 Global settings

characteristic:

The default format of numbers is provided on all pages

usage

(for spring): set the default number format in freemaker's configuration file, as follows:

The code is as follows

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>