3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Fix my previous buggy commit that changed Utils.bitcoinValueToFriendlyString

This commit is contained in:
Mike Hearn 2013-01-10 13:26:19 +01:00
parent d268270d7b
commit dd9e0d5d0d
2 changed files with 3 additions and 1 deletions

View File

@ -304,9 +304,10 @@ public class Utils {
value = value.negate();
BigDecimal bd = new BigDecimal(value, 8);
String formatted = bd.toPlainString(); // Don't use scientific notation.
int decimalPoint = formatted.indexOf(".");
// Drop unnecessary zeros from the end.
int toDelete = 0;
for (int i = formatted.length() - 1; i > 1; i--) {
for (int i = formatted.length() - 1; i > decimalPoint + 2; i--) {
if (formatted.charAt(i) == '0')
toDelete++;
else

View File

@ -50,6 +50,7 @@ public class UtilsTest {
@Test
public void testFormatting() {
assertEquals("1.00", bitcoinValueToFriendlyString(toNanoCoins(1, 0)));
assertEquals("1.23", bitcoinValueToFriendlyString(toNanoCoins(1, 23)));
assertEquals("0.001", bitcoinValueToFriendlyString(BigInteger.valueOf(COIN.longValue() / 1000)));
assertEquals("-1.23", bitcoinValueToFriendlyString(toNanoCoins(1, 23).negate()));