number formatting

This commit is contained in:
Sergey Solovyev 2011-12-15 12:45:15 +04:00
parent ca9aa1eed3
commit 23d6973194
5 changed files with 27 additions and 27 deletions

View File

@ -81,11 +81,6 @@ public enum CalculatorEngine {
this.engine.setUseGroupingSeparator(true);
}
@NotNull
public String format(@NotNull Double value, boolean round) {
return getEngine().format(value, round);
}
public static class Result {
@NotNull

View File

@ -172,11 +172,11 @@ public class NumberBuilder {
indexOfE = number.indexOf('E');
}
if (indexOfE < 0) {
formattedNumber = Numeric.toString(toDouble(number, nb), nb);
formattedNumber = toString(toDouble(number, nb), nb);
} else {
final String part;
if (indexOfDot != 0) {
part = Numeric.toString(toDouble(number.substring(0, indexOfE), nb), nb);
part = toString(toDouble(number.substring(0, indexOfE), nb), nb);
} else {
part = "";
}
@ -185,14 +185,14 @@ public class NumberBuilder {
} else {
final String integerPart;
if (indexOfDot != 0) {
integerPart = Numeric.toString(toDouble(number.substring(0, indexOfDot), nb), nb);
integerPart = toString(toDouble(number.substring(0, indexOfDot), nb), nb);
} else {
integerPart = "";
}
formattedNumber = integerPart + number.substring(indexOfDot);
}
} else {
formattedNumber = Numeric.toString(toDouble(number, nb), nb);
formattedNumber = toString(toDouble(number, nb), nb);
}
if (numberOffset != null) {
@ -205,6 +205,11 @@ public class NumberBuilder {
return result;
}
@NotNull
private static String toString(@NotNull Double value, @NotNull NumeralBase nb) {
return CalculatorEngine.instance.getEngine().format(value, nb);
}
public boolean isHexMode() {
return nb == NumeralBase.hex || ( nb == null && defaultNumeralBase == NumeralBase.hex);
}