Skip to content

Commit

Permalink
Specsize as percentage and px for issue #259
Browse files Browse the repository at this point in the history
printed the doubles with the minimum necessary precision
  • Loading branch information
phystem committed Apr 10, 2015
1 parent 035a11d commit c3c06a3
Showing 1 changed file with 10 additions and 2 deletions.
Expand Up @@ -89,17 +89,25 @@ protected Range convertRange(Range range, PageValidation pageValidation) throws
} }
} }


protected String getRangeAndValue(Range specRange, Range convertedRange, double realValue) { protected String getRangeAndValue(Range specRange, Range convertedRange, int realValue) {
String dimension = "px"; String dimension = "px";
String originalValue = realValue + dimension; String originalValue = realValue + dimension;
String rangeValue = convertedRange.getErrorMessageSuffix(); String rangeValue = convertedRange.getErrorMessageSuffix();
if (specRange.isPercentage()) { if (specRange.isPercentage()) {
double size = convertedRange.getFrom() / specRange.getFrom() * 100.0; double size = convertedRange.getFrom() / specRange.getFrom() * 100.0;
dimension = "%"; dimension = "%";
originalValue = format("%f%s [%s]", realValue / size * 100.0, dimension, originalValue); originalValue = format("%s%s [%s]", getInteger(realValue / size * 100.0), dimension, originalValue);
rangeValue = format("%s [%s]", specRange.getErrorMessageSuffix(dimension), convertedRange.toString()); rangeValue = format("%s [%s]", specRange.getErrorMessageSuffix(dimension), convertedRange.toString());
} }
return format("%s %s", originalValue, rangeValue); return format("%s %s", originalValue, rangeValue);
} }


private String getInteger(double d) {
if (d == (long) d) {
return String.format("%d", (long) d);
} else {
return String.format("%s", d);
}
}

} }

0 comments on commit c3c06a3

Please sign in to comment.