Bitcoin Forum
May 06, 2024, 12:29:34 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: consistent number of dp and rounding  (Read 867 times)
mav (OP)
Full Member
***
Offline Offline

Activity: 169
Merit: 107


View Profile
June 28, 2012, 03:13:47 AM
 #1

I've noticed that various applications use various number of decimal places in their implementations.

The bitcoin-qt client uses eight, which is what I've been following in my development, however some use less. Also, some clients use rounding, some use floor. This lack of consistency makes it difficult to implement a correct check of the expected balance of an address, because sometimes amounts may be slightly off. If I'm requesting to be paid to eight decimal places and a client only pays accurate to two because that's what their client supports, and my value gets rounded down, the customer will be missing .00XXXXXX bitcoin so they technically 'haven't paid'. I know it's only by small amounts, but if I end up using the 'lowest common decimal place' then the rounding errors could get really pathetic.

Can the community please pick a standard and go with it? Have your say here.

I think we should be using eight decimal places, rounded...
1714998574
Hero Member
*
Offline Offline

Posts: 1714998574

View Profile Personal Message (Offline)

Ignore
1714998574
Reply with quote  #2

1714998574
Report to moderator
"Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714998574
Hero Member
*
Offline Offline

Posts: 1714998574

View Profile Personal Message (Offline)

Ignore
1714998574
Reply with quote  #2

1714998574
Report to moderator
1714998574
Hero Member
*
Offline Offline

Posts: 1714998574

View Profile Personal Message (Offline)

Ignore
1714998574
Reply with quote  #2

1714998574
Report to moderator
Revalin
Hero Member
*****
Offline Offline

Activity: 728
Merit: 500


165YUuQUWhBz3d27iXKxRiazQnjEtJNG9g


View Profile
June 28, 2012, 03:27:47 AM
 #2

https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC)

tl;dr: standard practice is 8 decimal places, rounded.

      War is God's way of teaching Americans geography.  --Ambrose Bierce
Bitcoin is the Devil's way of teaching geeks economics.  --Revalin 165YUuQUWhBz3d27iXKxRiazQnjEtJNG9g
etotheipi
Legendary
*
expert
Offline Offline

Activity: 1428
Merit: 1093


Core Armory Developer


View Profile WWW
June 28, 2012, 03:34:50 AM
 #3

For reference, the correct way is to use long-integers to store the number of satoshis, which is 1e-8.  That is the smallest "atom" of a Bitcoin, limited artificially by the original design of the network.  There should be no rounding unless you're talking about rounding the 9th decimal place as the result of a calculation. 

In Armory, my coin2str() function truncates zeros from the right side so that users who only only deal with >= 0.01 BTC units and higher aren't overwhelmed with zero digits.  It is my policy that if there is precision down to 8 decimal places, I show it. 

It should never be stored as a float or double.  Set  a constant ONE_BTC=100000000 and then when you want to specify something in Bitcoins, say long(2.5*ONE_BTC).   And a coin2str() function to convert from Satoshis back to a pleasant string representation.

Founder and CEO of Armory Technologies, Inc.
Armory Bitcoin Wallet: Bringing cold storage to the average user!
Only use Armory software signed by the Armory Offline Signing Key (0x98832223)

Please donate to the Armory project by clicking here!    (or donate directly via 1QBDLYTDFHHZAABYSKGKPWKLSXZWCCJQBX -- yes, it's a real address!)
mb300sd
Legendary
*
Offline Offline

Activity: 1260
Merit: 1000

Drunk Posts


View Profile WWW
June 28, 2012, 03:48:11 AM
 #4

I use decimal in any calculation involving bitcoins. It should have enough precision to store every bitcoin that will ever exist in nano-satoshis... Hopefully someday we'll need nano-satoshis  Grin

1D7FJWRzeKa4SLmTznd3JpeNU13L1ErEco
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!