简介
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信息,目前还不清楚如何将Fraction类型转换为Double。
问题
可以将Apache Common Math的Fraction转换为Double?
答案 0 :(得分:1)
根据乌得勒支的建议,以供将来参考:
通过此处的API:http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/fraction/Fraction.html#doubleValue%28%29,Fraction
具有成员方法doubleValue()
。