如何将数字转换为百分比并得到小数

How to convert a number to percentage and get a decimal

我正在使用 JavaFX 编写计算器程序。如何获取小数形式的数字百分比?例如 45% 会给出 0.45 2% 会给我 0.02 等等 谢谢

这只是 return 用户输入的整数,例如 45% 就是 45 2% 将是 2 等等

            bt1.setOnAction(e->{
                    String result = textArea.getText(); 
                    double n = Double.parseDouble(result);
                    double percent = n * 100 / 100;
                    textArea.appendText(Double.toString(percent));
            });

更改此行: 双倍百分比 = n * 100 / 100; 到 双倍百分比 = n / 100;

试试这个:

bt1.setOnAction(e->{
String result = textArea.getText(); 
String replaceString = result.replace("%","");
double n = Double.parseDouble(replaceString);
double percent = n / 100;
textArea.appendText(Double.toString(percent));
});