1. Page Operation formatting numbers
On the page sometimes use the number of operations, after the operation will appear 1.5999999999999 such a long number, need to format numbers, such as the retention of two valid digits
First import this label
<% @ taglib URI = " http://java.sun.com/jsp/jstl/fmt " prefix = " FMT " %>
Then use the label language
<type= "number" value= "${cost-beannums}" pattern = "0.00" maxfractiondigits = "2" />
2. Pass the value to the page before formatting the number
DecimalFormat decimalformat=New DecimalFormat ("#0.00"); // the character format of the constructed method here if the decimal place is less than 2 bits, it will be 0. String P=decimalformat.format (cost); // format returns a string
This time the value to the page is a string form, if the use of El expression, the following is wrong, because cost is a string form, can not compare size
<C:whenTest= "${beannums! = 0 && cost>beannums}"><spanclass= "Ml50 Pay_by_cash_span">¥<Fmt:formatnumbertype= "Number"value= "${cost-beannums}"pattern= "0.00"maxfractiondigits= "2"/></span></C:when>
So we need to do the math first.
<C:whenTest= "${beannums! = 0 && cost-beannums>0}"><spanclass= "Ml50 Pay_by_cash_span">¥<Fmt:formatnumbertype= "Number"value= "${cost-beannums}"pattern= "0.00"maxfractiondigits= "2"/></span></C:when>
Float retains two decimal places