Apache Common Math的分数将翻倍

时间:2014-06-26 21:09:42

标签: java apache math

简介

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

根据thisthis信息,目前还不清楚如何将Fraction类型转换为Double。

问题

可以将Apache Common Math的Fraction转换为Double?

1 个答案:

答案 0 :(得分:1)

根据乌得勒支的建议,以供将来参考:

通过此处的API:http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/fraction/Fraction.html#doubleValue%28%29Fraction具有成员方法doubleValue()