setScale()
BigDecimal
will do this for you on the server side
import java.math.BigDecimal; public class Main{ public static void main(String ar[]){ float number = 123.123456F; BigDecimal numberBigDecimal = new BigDecimal(number); System.out.println(numberBigDecimal); numberBigDecimal = numberBigDecimal .setScale(2, BigDecimal.ROUND_HALF_UP); System.out.println(numberBigDecimal); } }
source share