Only use additional decimal places for coins when explicitly required

This commit is contained in:
Christoph Atteneder 2018-02-14 13:47:11 +01:00
parent 5db9e208c9
commit 727acb8ab5
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
3 changed files with 18 additions and 28 deletions

View File

@ -410,7 +410,7 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty)
setText(formatter.formatCoin(offerListItem.offer.getAmount()));
setText(formatter.formatCoin(offerListItem.offer.getAmount(),4));
else
setText("");
}
@ -418,29 +418,6 @@ public class OfferBookChartView extends ActivatableViewAndModel<VBox, OfferBookC
}
});
// Lets remove that as it is not really relevant and seems to be confusing to some users
// accumulated
/* TableColumn<OfferListItem, OfferListItem> accumulatedColumn = new AutoTooltipTableColumn<>(Res.get("shared.sumWithCur", Res.getBaseCurrencyCode()));
accumulatedColumn.setMinWidth(100);
accumulatedColumn.setSortable(false);
accumulatedColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
accumulatedColumn.setCellFactory(
new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {
@Override
public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
return new TableCell<OfferListItem, OfferListItem>() {
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty)
setText(formatter.formatRoundedDoubleWithPrecision(offerListItem.accumulated, 4));
else
setText("");
}
};
}
});
*/
tableView.getColumns().add(volumeColumn);
tableView.getColumns().add(amountColumn);
tableView.getColumns().add(priceColumn);

View File

@ -81,9 +81,21 @@ public class BSFormatter {
///////////////////////////////////////////////////////////////////////////////////////////
public String formatCoin(Coin coin) {
return formatCoin(coin, -1);
}
@NotNull
public String formatCoin(Coin coin, int decimalPlaces) {
final int repetitions = decimalPlaces;
if (coin != null) {
try {
return coinFormat.noCode().minDecimals(4).repeatOptionalDecimals(1,4).format(coin).toString();
if (decimalPlaces < 0) {
return coinFormat.noCode().format(coin).toString();
} else {
final int decimals = decimalPlaces/repetitions;
return coinFormat.noCode().minDecimals(repetitions).repeatOptionalDecimals(decimals, repetitions).format(coin).toString();
}
} catch (Throwable t) {
log.warn("Exception at formatBtc: " + t.toString());
return "";

View File

@ -96,7 +96,8 @@ public class BSFormatterTest {
@Test
public void testFormatCoin() {
assertEquals("1.0000", formatter.formatCoin(oneBitcoin));
assertEquals("1.00", formatter.formatCoin(oneBitcoin));
assertEquals("1.0000", formatter.formatCoin(oneBitcoin, 4));
assertEquals("0.000001", formatter.formatCoin(make(a(CoinMaker.Coin).but(with(satoshis, 100L)))));
assertEquals("0.00000001", formatter.formatCoin(make(a(CoinMaker.Coin).but(with(satoshis, 1L)))));
}
@ -145,7 +146,7 @@ public class BSFormatterTest {
when(offer.getMinAmount()).thenReturn(Coin.valueOf(10000000));
when(offer.getAmount()).thenReturn(Coin.valueOf(10000000));
assertEquals("0.1000", formatter.formatAmountWithMinAmount(offer));
assertEquals("0.10", formatter.formatAmountWithMinAmount(offer));
}
@Test
@ -155,7 +156,7 @@ public class BSFormatterTest {
when(offerPayload.getMinAmount()).thenReturn(10000000L);
when(offerPayload.getAmount()).thenReturn(20000000L);
assertEquals("0.1000 - 0.2000", formatter.formatAmountWithMinAmount(offer));
assertEquals("0.10 - 0.20", formatter.formatAmountWithMinAmount(offer));
}
@Test