The BTC shows 10^8 times more than what is received in the account

2

1

I work with Java/Maven/JSP app with BitcoinJ and I have transfer about 0.0048 BTC from a testnet faucet. However, after receiving, I see that my account has balance of 480000.00 BTC.

enter image description here

This is the method I have used to get the Satoshi Coin.

public Coin getBalance() {
        return balance;
    }

I have checked the code and at least my backend part looks normal to me. How to approach to this problem?

Arefe

Posted 2017-05-31T04:12:04.390

Reputation: 203

Answers

3

Apparently the app shows the amount as Satoshi (the smallest unit) instead of BTC. For internal calculations that's ok because it avoids rounding errors, but for input and output you should scale by an appropriate factor (10^8 for BTC, or 10^5 for mBTC).

Hans-Martin Mosner

Posted 2017-05-31T04:12:04.390

Reputation: 514

2

Yes, and in bitcoinj there are actually two classes for formatting Coin values for humans: MonetaryFormat and BtcFormat. I strongly suggest using one of the two.

Here's an example:

Wallet wallet = <initialize wallet here>
String friendlyFormat = BtcFormat.getInstance().format(wallet.getBalance());

Andreas Schildbach

Posted 2017-05-31T04:12:04.390

Reputation: 499

How to convert Satoshies to BTC in Java?Arefe 2017-05-31T07:51:40.467

What does the wallet.getBalance() returns? I have tried with several ways and none actually works for me. The method I use to get the Satoshi Coin is

public Coin getBalance() { return balance; }

How can I get the correct value in BTC? I have also tried with balance.leftShift(8)Arefe 2017-06-01T04:21:12.720