Remove round preference
This commit is contained in:
@@ -36,8 +36,6 @@ public class JsclMathEngine implements MathEngine {
|
||||
public static final AngleUnit DEFAULT_ANGLE_UNITS = AngleUnit.deg;
|
||||
public static final NumeralBase DEFAULT_NUMERAL_BASE = NumeralBase.dec;
|
||||
public static final char GROUPING_SEPARATOR_DEFAULT = ' ';
|
||||
public static final char GROUPING_SEPARATOR_NO = 0;
|
||||
public static final int MAX_FRACTION_DIGITS = 20;
|
||||
@Nonnull
|
||||
private static JsclMathEngine instance = new JsclMathEngine();
|
||||
@Nonnull
|
||||
@@ -49,10 +47,9 @@ public class JsclMathEngine implements MathEngine {
|
||||
return new NumberFormatter();
|
||||
}
|
||||
};
|
||||
private char groupingSeparator = GROUPING_SEPARATOR_NO;
|
||||
private boolean roundResult = false;
|
||||
private char groupingSeparator = NumberFormatter.NO_GROUPING;
|
||||
private int notation = FSE_NONE;
|
||||
private int precision = 5;
|
||||
private int precision = NumberFormatter.MAX_PRECISION;
|
||||
@Nonnull
|
||||
private AngleUnit angleUnits = DEFAULT_ANGLE_UNITS;
|
||||
@Nonnull
|
||||
@@ -182,7 +179,7 @@ public class JsclMathEngine implements MathEngine {
|
||||
private NumberFormatter prepareNumberFormatter(@Nonnull NumeralBase nb) {
|
||||
final NumberFormatter nf = numberFormatter.get();
|
||||
nf.setGroupingSeparator(hasGroupingSeparator() ? getGroupingSeparatorChar(nb) : NumberFormatter.NO_GROUPING);
|
||||
nf.setPrecision(roundResult ? precision : NumberFormatter.NO_ROUNDING);
|
||||
nf.setPrecision(precision);
|
||||
switch (notation) {
|
||||
case FSE_ENG:
|
||||
nf.useEngineeringFormat(NumberFormatter.DEFAULT_MAGNITUDE);
|
||||
@@ -264,7 +261,7 @@ public class JsclMathEngine implements MathEngine {
|
||||
|
||||
ungroupedValue = to.toString(new BigDecimal(value).toBigInteger());
|
||||
} catch (NotIntegerException e) {
|
||||
ungroupedValue = to.toString(value, roundResult ? precision : MAX_FRACTION_DIGITS);
|
||||
ungroupedValue = to.toString(value, precision);
|
||||
}
|
||||
|
||||
return addGroupingSeparators(to, ungroupedValue);
|
||||
@@ -309,7 +306,7 @@ public class JsclMathEngine implements MathEngine {
|
||||
}
|
||||
|
||||
private boolean hasGroupingSeparator() {
|
||||
return groupingSeparator != JsclMathEngine.GROUPING_SEPARATOR_NO;
|
||||
return groupingSeparator != NumberFormatter.NO_GROUPING;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -347,10 +344,6 @@ public class JsclMathEngine implements MathEngine {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setRoundResult(boolean roundResult) {
|
||||
this.roundResult = roundResult;
|
||||
}
|
||||
|
||||
public void setPrecision(int precision) {
|
||||
this.precision = precision;
|
||||
}
|
||||
|
@@ -38,8 +38,6 @@ public interface MathContext {
|
||||
|
||||
void setNumeralBase(@Nonnull NumeralBase numeralBase);
|
||||
|
||||
void setRoundResult(boolean roundResult);
|
||||
|
||||
void setPrecision(int precision);
|
||||
|
||||
void setGroupingSeparator(char separator);
|
||||
|
@@ -1,17 +1,21 @@
|
||||
package org.solovyev.common;
|
||||
|
||||
import midpcalc.Real;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import midpcalc.Real;
|
||||
|
||||
import static java.lang.Math.pow;
|
||||
import static midpcalc.Real.NumberFormat.*;
|
||||
import static midpcalc.Real.NumberFormat.FSE_ENG;
|
||||
import static midpcalc.Real.NumberFormat.FSE_FIX;
|
||||
import static midpcalc.Real.NumberFormat.FSE_NONE;
|
||||
import static midpcalc.Real.NumberFormat.FSE_SCI;
|
||||
|
||||
public class NumberFormatter {
|
||||
|
||||
public static final int NO_GROUPING = 0;
|
||||
public static final char NO_GROUPING = 0;
|
||||
public static final int NO_ROUNDING = -1;
|
||||
public static final int DEFAULT_MAGNITUDE = 5;
|
||||
public static final int MAX_PRECISION = 16;
|
||||
@@ -94,7 +98,6 @@ public class NumberFormatter {
|
||||
final BigInteger absValue = value.abs();
|
||||
final boolean simpleFormat = useSimpleFormat(radix, absValue);
|
||||
|
||||
final int effectivePrecision = precision == NO_ROUNDING ? MAX_PRECISION : precision;
|
||||
if (simpleFormat) {
|
||||
numberFormat.fse = FSE_FIX;
|
||||
} else if (format == FSE_NONE) {
|
||||
@@ -105,7 +108,7 @@ public class NumberFormatter {
|
||||
numberFormat.fse = format;
|
||||
}
|
||||
numberFormat.thousand = groupingSeparator;
|
||||
numberFormat.precision = effectivePrecision;
|
||||
numberFormat.precision = Math.max(0, Math.min(precision, MAX_PRECISION));
|
||||
numberFormat.base = radix;
|
||||
numberFormat.maxwidth = simpleFormat ? 100 : 30;
|
||||
|
||||
|
Reference in New Issue
Block a user