例如
Float = 2.10;
我如何只显示.10或2
我做到了
DecimalFormat I = new DecimalFormat("#");
System.out.println(I.format(answer));
但是我怎么做最后的小数
最佳答案
您可以按照以下步骤进行操作:
public class Main {
public static void main(String[] args) {
Float f1 = (float) 2.10;
String str = String.format("%.2f", f1);
System.out.println(str.substring(str.indexOf(".")));
}
}
输出:
.10
选中this以了解有关
Formatter
的更多信息。
关于java - 如何在JLabel中显示 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60919672/