<p>The Coin.valueOf(long) static constructor takes Satoshis as an input. You can use one of the toString/toFriendlyString/toPlainString methods to derive a human readable value string.</p>

CC BY-SA 3.0
2017-06-01T06:26:27.340Z
2017-06-01T06:26:27.340Z
Andreas
<p>I get the value of money in Satoshi and I would like to have it in BTC. I develop the app in <code>Java/Maven/JSP</code> and use BitcoinJ for the framework. I use the code, </p>

<pre><code>    public Coin getBalance() {

        int fac = (int) Math.pow(10, 8);
        return balance.div(fac);
    }
</code></pre>

<p>In the JSP, I use,</p>

<pre><code>&lt;%
    DecimalFormat decimalFormat = new DecimalFormat("#0.00");
%&gt;
&lt;div class="fild_value"&gt;
                    &lt;%= decimalFormat.format(model.getBalance().getValue()) %&gt;&amp;nbsp; BTC
&lt;/div&gt;
</code></pre>

<p>In this way, I miss the value after the decimal. For example, I get <code>1.00 BTC</code> when I suppose to get <code>1.68 BTC</code>. How to convert Satoshi to BTC in Java properly?</p>

CC BY-SA 3.0
2017-05-31T09:44:24.030Z
`value` times `100million` ?
Penguin9
CC BY-SA 3.0
2017-05-31T09:50:08.367Z
The `balance` provides the value in satoshi and the mentioned code in the `getBalance` method converts it to the BTC. `[1 BTC =  10^8 Satoshi]`. Now, after converting in the fashion, I was not getting the value after the decimal. How to get the value properly?
Arefe
CC BY-SA 3.0
2017-05-31T11:50:22.317Z
Note: int/int = int, so 4/3 =1. I am not aware of the specifics of your problem, but the solution must to convert either the balance in satoshi or fac(10^8) to float and use it for division.
sanket1729
CC BY-SA 3.0
2017-06-01T04:17:12.223Z
Tried the way suggested and doesn't work for me.
Arefe
<bitcoinj><java>
How to convert Satoshi to BTC in Java?
Arefe
# How to convert Satoshi to BTC in Java?

(Asked by: username_0 on 2017-05-31)

I get the value of money in Satoshi and I would like to have it in BTC. I develop the app in `Java/Maven/JSP` and use BitcoinJ for the framework. I use the code,

```
    public Coin getBalance() {

        int fac = (int) Math.pow(10, 8);
        return balance.div(fac);
    }

```

In the JSP, I use,

```
<%
    DecimalFormat decimalFormat = new DecimalFormat("#0.00");
%>
<div class="fild_value">
                    <%= decimalFormat.format(model.getBalance().getValue()) %>&nbsp; BTC
</div>

```

In this way, I miss the value after the decimal. For example, I get `1.00 BTC` when I suppose to get `1.68 BTC`. How to convert Satoshi to BTC in Java properly?

**Tags:** bitcoinj, java

> **Comments:**
> **username_1**: `value` times `100million` ?  
> **username_0**: The `balance` provides the value in satoshi and the mentioned code in the `getBalance` method converts it to the BTC. `[1 BTC =  10^8 Satoshi]`. Now, after converting in the fashion, I was not getting the value after the decimal. How to get the value properly?  
> **username_2**: Note: int/int = int, so 4/3 =1. I am not aware of the specifics of your problem, but the solution must to convert either the balance in satoshi or fac(10^8) to float and use it for division.  
> **username_0**: Tried the way suggested and doesn't work for me.  

---

## 1 answers

### Answer by username_3 on 2017-06-01. Score: 2

The Coin.valueOf(long) static constructor takes Satoshis as an input. You can use one of the toString/toFriendlyString/toPlainString methods to derive a human readable value string.


---

