Java Code Examples for org.apache.commons.lang3.math.NumberUtils.isParsable()

The following are Jave code examples for showing how to use isParsable() of the org.apache.commons.lang3.math.NumberUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: exam   File: ClozeTestAnswer.java   Source Code and License Vote up 6 votes
private boolean isCorrectNumericAnswer(Element blank, Map<String, String> answers) {
    String key = blank.attr("id");
    if (!answers.containsKey(key) || answers.get(key) == null) {
        return false;
    }
    String answerText = answers.get(key);
    answerText = answerText.trim();
    if (!NumberUtils.isParsable(answerText)) {
        return false;
    }
    String precisionAttr = blank.attr("precision");
    Double answer = Double.parseDouble(answerText);
    Double correctAnswer = Double.parseDouble(blank.text().trim());
    Double precision = precisionAttr == null ? 0.0 : Double.parseDouble(precisionAttr);
    return correctAnswer - precision <= answer && answer <= correctAnswer + precision;
}