log error on infinity in offer book chart view without popup #1340

This commit is contained in:
woodser 2024-10-20 12:49:05 -04:00
parent bc1cfe3ba0
commit 123a2a8487

View File

@ -207,16 +207,21 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
@Override
public String toString(Number object) {
final double doubleValue = (double) object;
if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
final String withCryptoPrecision = FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, cryptoPrecision);
if (withCryptoPrecision.startsWith("0.0")) {
return FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, 8).replaceFirst("0+$", "");
try {
final double doubleValue = (double) object;
if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
final String withCryptoPrecision = FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, cryptoPrecision);
if (withCryptoPrecision.startsWith("0.0")) {
return FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, 8).replaceFirst("0+$", "");
} else {
return withCryptoPrecision.replaceFirst("0+$", "");
}
} else {
return withCryptoPrecision.replaceFirst("0+$", "");
return df.format(Double.parseDouble(FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, 0)));
}
} else {
return df.format(Double.parseDouble(FormattingUtils.formatRoundedDoubleWithPrecision(doubleValue, 0)));
} catch (IllegalArgumentException e) {
log.error("Error converting number to string, tradeCurrency={}, number={}\n", code, object, e);
return "NaN"; // TODO: occasionally getting invalid number
}
}