按百分比双重修改

Double modification by percentage

我正在尝试按百分比修改 double。

例子

我有双10.0.

我需要按百分比修改这个 double 以获得以下输出:

Example Output:
50% -> 20.0
75% -> 15.0
100% -> 10.0
200% -> 5.0

我怎样才能做到这一点,是否有数学术语?

简单方法:

double startValue = 10;
double percent = 50;
double tempValue = startValue * (percent*.01);
double finalValue = startValue + tempValue;

这是一个简单的除法:

System.out.println(10D / 0.5);   // 20.0
System.out.println(10D / 0.75);  // 15.0
System.out.println(10D / 1);     // 10.0
System.out.println(10D / 2);     // 5.0

Java会变成这样

double percentage = Double.parseDouble(percentageValue.substring("%", "")) / 100;
double d = doubleValue;
double result = d / percentage;

这允许您这样做:

input: percentageValue, doubleValue
output: result

测试:

input: 100%, 20
output: 10

我不认为有一个术语。 (如果我错了,有人纠正我。:)