« Rapid Java Development Using Spring, Hibernate, Eclipse and Other Open Source Tools | Main | JSP / XSLT combo »

July 18, 2006

Rounding monetary values to two decimal places in Java

/*Use banker's rounding to round the value to two decimal places. Multiply by 100 then use Math.rint to round to nearest integer, then finally divide by 100 again.*/

return(Math.rint(addedVat*100.0)/100.0);


Tags: Java

Posted by pj at July 18, 2006 04:15 PM

Comments