Java 如何显示3个小数点而不进行取整?

Java 如何显示3个小数点而不进行取整?,java,android,decimal,bigdecimal,number-formatting,Java,Android,Decimal,Bigdecimal,Number Formatting,我正在做一个应用程序,需要显示3个小数点,我实现了这一点 数字CIMAL,但问题是如果第4位大于5,则第3位 自动增加。我想显示ex的确切数字: Result : 100.2356 Output : 100.236 // Applying NumberDecimal 需要此输出:100.235//我需要此输出 This is my function : public String setdecimal(float a) { NumberFor

我正在做一个应用程序,需要显示3个小数点,我实现了这一点 数字CIMAL,但问题是如果第4位大于5,则第3位 自动增加。我想显示ex的确切数字:

Result           : 100.2356 
Output           : 100.236  // Applying NumberDecimal
需要此输出:100.235//我需要此输出

This is my function :
public String setdecimal(float a) 
{
   NumberFormat formatter = new DecimalFormat("##.###");
   return formatter.format(a);

}
使用:


根据您处理负数的方式,您还可以使用向零舍入的
RoundingMode.DOWN

您可以使用下面的方法截断点后的数字,而不舍入值

public static String getThreeDigitDisplayValueFromFloat(float value) {

    String price = new DecimalFormat("##.###").format(value);
    return String.format(Locale.getDefault(), "%.3f", Float.parseFloat(price));
}

它说的是不加修饰的
public static String getThreeDigitDisplayValueFromFloat(float value) {

    String price = new DecimalFormat("##.###").format(value);
    return String.format(Locale.getDefault(), "%.3f", Float.parseFloat(price));
}