简体   繁体   English

在DecimalFormat上设置RoundingMode时遇到问题

[英]Trouble with setting RoundingMode on DecimalFormat

This might be kind of a dumb question, but I'm stuck on it. 这可能是一个愚蠢的问题,但我仍然坚持。

I'm trying to set the RoundingMode on a DecimalFormat . 我正在尝试在DecimalFormat上设置RoundingMode

DecimalFormat df = new DecimalFormat("###.##");
df.setRoundingMode(RoundingMode.HALF_UP);

However, the code looks fine to me and it looks the same as many examples I have seen. 但是,代码对我来说看起来不错,并且看起来与我看到的许多示例相同。

The error on setRoundingMode() is: setRoundingMode()上的错误是:

***The method setRoundingMode(RoundingMode) is undefined for the type DecimalFormat***

It suggests to cast df to an Object , but that doesn't solve anything... 它建议将df转换为Object ,但这并不能解决任何问题...

Any suggestions? 有什么建议么?

EDIT 编辑

I am using ver. 我正在使用ver。 1.7 1.7

Below I changed the compliance level to 1.6 yet no difference. 下面,我将合规性级别更改为1.6,但没有差异。

Java编译器

Thank you in advance for the help! 预先感谢您的帮助!

Try System.out.println(System.getProperty("java.version")); 试试System.out.println(System.getProperty("java.version")); and be sure that your jre version really is 1.6 or higher 并确保您的jre版本确实是1.6或更高版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM