In jsp page After decimal i need only 2 values(for ex:477.74)
Hi Guys,
I displaying report for work wise progress in jsp. At end of line i calculating total amount of Contract . In my result it is displaying 477.74999999994. For reference you can see attached screen shot file. But i want result in this format 477.74(i dont want to be round off).
I attached jsp page for your reference .
Please help me & need code for that
Re: In jsp page After decimal i need only 2 values(for ex:477.74)
Hi,
I suppose the amount is stored in a BigDecimal type.
Create an utility Java Class a static method like this:
Code:
public class MyUtils{
public static String truncateBigDecimal(BigDecimal bg, Locale loc , int decimals) {
bg = bg.setScale(decimals, RoundingMode.DOWN);
DecimalFormat df = new DecimalFormat();
if (loc != null)
df.setDecimalFormatSymbols(new DecimalFormatSymbols(loc));
return df.format(bg);
}
}
From your JSP, first import this util class, and then print amount with appropriate format:
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.