介绍
setComputerizedFractionAnswer
private void setComputerizedFractionAnswer(double randomDigitOne,
double randomDigitTwo, MathematicalOperator mathematicalOperator) {
this.computerizedFractionAnswer = fraction(randomDigitOne).add(
fraction(randomDigitTwo));
}
getComputerizedFractionAnswer
private Fraction getComputerizedFractionAnswer() {
return computerizedFractionAnswer;
}
将从Servlet发布Double或Fraction答案,随后将调用以下方法:
public String validateAnswer(double d) {
if (getComputerizedAnswer() == d || getComputerizedFractionAnswer() == d) {
return "Correct";
}
return "Wrong";
}
导致以下问题:
Incompatible operand types Fraction and double
。基于this和this信息,尚不清楚如何将小数类型转换为Double。
题
是否可以将Apache Common Math的分数转换为Double?
最佳答案
Per utrecht的建议,以供将来参考:
从此处的API:http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/fraction/Fraction.html#doubleValue%28%29,Fraction
具有成员方法doubleValue()
。
关于java - Apache Common Math的分数加倍,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24440283/