In Java:
Import java.math.bigdecimal;import Java.text.decimalformat;import java.text.numberformat;public class format { Double F = 111231.5585; public void M1 () { BigDecimal bg = new BigDecimal (f); Double f1 = Bg.setscale (2, bigdecimal.round_half_up). doublevalue (); System.out.println (f1); } /** * DecimalFormat conversion is easiest * /public void m2 () { decimalformat df = new DecimalFormat ("#.00"); System.out.println (df.format (f)); /** * String.Format printing easiest */public void M3 () { System.out.println (string.format ("%.2f", f)); } Public void M4 () { numberformat nf = numberformat.getnumberinstance (); Nf.setmaximumfractiondigits (2); System.out.println (nf.format (f)); public static void main (string[] Args) { format f = new format (); F.M1 (); F.M2 (); F.M3 (); F.M4 (); }}
Results:
111231.56
111231.56
111231.56
111,231.56----------------------------------------------------------------------------------------------------- -------------------------------------------------------an El Expression:import <%@ taglib prefix= "fmt" uri= "http://java.sun.com/jsp/jstl/fmt"%><fmt:formatnumber value= "${}" pattern= "#.00"/>
<fmt:formatnumber value= "${num}" maxfractiondigits= "0"/>
<fmt:formatnumber value= "${failallsum}" pattern= "#,###.##"/>
Methods for preserving decimals in java, el expressions