I am using toFixed(2) in client side(javascript). But in the server side(java) i have to recalculate. how can i do this?
setScale()
of BigDecimal
will do it for you on 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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With