<p>The amounts returned by Bitcoin Core are accurate. They are not actually doubles; they're just output that way for convenience. Bitcoin Core internally uses a int64 and the amounts are satoshis. When outputting for users, the int64 is used and a string formatter just puts a decimal point in the appropriate place. Since it already is exact, you just need to drop the decimal point. The easiest way to do this is to take the output as a string, remove the decimal point, and convert that string to an integer.</p>

CC BY-SA 4.0
2019-03-13T09:28:50.423Z
Thank you for your quick reply! I'm using jsonrpccpp to communicate with the bitcoin core using RPC. Since you say that the bitcoin core is accurate, the jsonrpccpp allows me to parse the information and view the amount as Double, String etc. Double seems to be the correct amount. how do i make sure, that the parser it self stores it correctly?
Haim
CC BY-SA 4.0
2019-03-13T14:40:08.887Z
I suggest that you store it as a string and not as a double.
Ava Chow
CC BY-SA 4.0
2019-03-14T07:27:55.177Z
i tried your approach. I've converted 0.00018281 BTC to Satoshi's in two ways. from double i got 18281 Satoshi's and from string i got 18280999999999999 satoshi's. it seems like the string isn't converting the value properly (from the jsonrpccpp). any suggestions? (all i did in the string was to remove the '.' character)
Haim
CC BY-SA 4.0
2019-03-14T14:52:31.360Z
Sorry, I am not familiar with how  jsonrpccpp works.
Ava Chow
CC BY-SA 4.0
2019-03-12T14:48:57.430Z
2019-03-12T14:48:57.430Z
Ava Chow
<p>I am developing a bitcoin wallet for education purposes, and i'm working on a <code>getbalance</code> method that given an address i return the balance of the address. </p>

<p>Problem is, when communicating via the RPC protocol i am given the amount in a double format rather than satoshi (int). And i would like to provide the amount in Satoshi's.</p>

<p>How do i properly convert the double amount, into uint64 satoshi amount?
Since double is not an accurate value, how do I make sure that my "users" get the correct value for their balance, or on their transactions?</p>

<p>Thanks,</p>

<wallet><balance><c++><satoshi>
How to get amount in RPC
Haim
# How to get amount in RPC

(Asked by: username_0 on 2019-03-12)

I am developing a bitcoin wallet for education purposes, and i'm working on a `getbalance` method that given an address i return the balance of the address.

Problem is, when communicating via the RPC protocol i am given the amount in a double format rather than satoshi (int). And i would like to provide the amount in Satoshi's.

How do i properly convert the double amount, into uint64 satoshi amount?
Since double is not an accurate value, how do I make sure that my "users" get the correct value for their balance, or on their transactions?

Thanks,

**Tags:** wallet, balance, c++, satoshi


---

## 1 answers

### Answer by username_1 on 2019-03-12. Score: 1

The amounts returned by Bitcoin Core are accurate. They are not actually doubles; they're just output that way for convenience. Bitcoin Core internally uses a int64 and the amounts are satoshis. When outputting for users, the int64 is used and a string formatter just puts a decimal point in the appropriate place. Since it already is exact, you just need to drop the decimal point. The easiest way to do this is to take the output as a string, remove the decimal point, and convert that string to an integer.

> **Comments:**
> **username_0**: Thank you for your quick reply! I'm using jsonrpccpp to communicate with the bitcoin core using RPC. Since you say that the bitcoin core is accurate, the jsonrpccpp allows me to parse the information and view the amount as Double, String etc. Double seems to be the correct amount. how do i make sure, that the parser it self stores it correctly?  
> **username_1**: I suggest that you store it as a string and not as a double.  
> **username_0**: i tried your approach. I've converted 0.00018281 BTC to Satoshi's in two ways. from double i got 18281 Satoshi's and from string i got 18280999999999999 satoshi's. it seems like the string isn't converting the value properly (from the jsonrpccpp). any suggestions? (all i did in the string was to remove the '.' character)  
> **username_1**: Sorry, I am not familiar with how  jsonrpccpp works.  

---

