我想在 DecimalFormat 上将舍入模式设置为 HALF_UP,但 eclipse 告诉我 setRoundingMode() 在 DecimalFormat 类上不可用。我的项目属性(以及整个 Eclipse 属性)使用的是 1.6 编译器。developer.android.com 网站说我可以使用 Java 5 或 6,所以我不确定问题出在哪里。
import java.math.RoundingMode;
import java.text.DecimalFormat;
completedValueFormatter = NumberFormat.getNumberInstance();
DecimalFormat completedDecimalFormat = (DecimalFormat)completedValueFormatter;
completedDecimalFormat.setRoundingMode(RoundingMode.HALF_UP);
我还尝试使用 android 工具生成基于 ant 的项目,在项目中尝试了此代码,也得到了相同的编译错误。所以它似乎与 Eclipse 无关。它似乎与Android API有关。
有什么建议么?