将Float格式化为n个小数位我需要将float格式化为“n”个小数位。正在尝试BigDecimal,但返回值不正确...public static float Redondear(float pNumero, int pCantidadDecimales) {
// the function is call with the values Redondear(625.3f, 2)
BigDecimal value = new BigDecimal(pNumero);
value = value.setScale(pCantidadDecimales, RoundingMode.HALF_EVEN); // here the value is correct (625.30)
return value.floatValue(); // but here the values is 625.3}我需要返回一个浮点值,其中包含我指定的小数位数。我不需要Float价值回报Double。
添加回答
举报
0/150
提交
取消