문제

I'm getting the String type decimal number from the local database.

And

I viewed three decimal places in my UI application(html page).so now i need to limit it as 2 deciaml places.

Example String Amount = "123.786";

change the amount decimal value to "123.78"(to be displayed in my web application)

Please help to limit it to two decimal places.

I tried using Stringutils functionality but i can't absorb it.

도움이 되었습니까?

해결책

 String Amount = "123.786";
 String value= String.format("%.2f", Float.valueOf(Amount));

or 

BigDecimal value = new BigDecimal(Amount).setScale(2, BigDecimal.ROUND_HALF_UP);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top