What is the best way to get a float value rounded to two decimal digits?
For example, I have float f1 = 123.9876
.
But I need 123.98
.
Are there any annotations which can do this?
What is the best way to get a float value rounded to two decimal digits?
For example, I have float f1 = 123.9876
.
But I need 123.98
.
Are there any annotations which can do this?
You can do it manually with BigDecimal Class
float f=123.456778f;
BigDecimal decimalNo=new BigDecimal(f);
decimalNo=decimalNo.setScale(2,BigDecimal.ROUND_HALF_UP);
decimalNo = 123.45