Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个程序,我尝试更改我的双精度数的小数位数。我有一本书告诉我做 import java.text.* 然后这个:
NumberFormat nf = new NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(1);
但在第一行我收到错误“NumberFormat.getNumberInstance() 无法解析为类型”。为什么我做不到?
你的问题在这里:NumberFormat nf = new NumberFormat.getNumberInstance();。您需要new从那里删除关键字才能得到这个:NumberFormat nf = NumberFormat.getNumberInstance();。您正在访问一个static方法,您不需要new这里。
NumberFormat nf = new NumberFormat.getNumberInstance();
new
NumberFormat nf = NumberFormat.getNumberInstance();
static