Bitcoin data type

Hey! I’m new here, and it looks like it is a great community.

I was wondering if anybody had to come across bitcoin transactions.

The smallest Bitcoin unit is 1e-8, float numbers are not trustable at all, so I was looking for a solution, either a package that takes care of that or maybe a trick i’m not aware of.

Thanks guys :slight_smile:

Store 1 BC as 1,000,000. Display as 1. AFAIK that’s the internal representation anyway.

Maybe I’m of 1 or 2 multiples of 10, but hey, you’ll figure that out :wink:

I was thinking about that too, the problem with that is that this number rappresent an actual monetary value. and if a conversion from bigint to float goes wrong potentially an user can cashout 1000’s of bitcoin and it’s not ideal.

Where do you want to convert from bigint or float or vice versa?

Stick to whatever integer type you choose and only use that.

The following shows an example using a regular currency, internally stored with a precision of 10e-6, displayed with 10e-2:

https://play.golang.org/p/t7Lvd0R3bcV

PS: I’m pretty sure that there are already fixed point packages available for golang, or even specialised currency packages. Try to find those and use them, that will be much less error prone than what you might come up with by yourself.

I have not used this for anything related to Bitcoin, but https://github.com/shopspring/decimal is nice for dealing with money/decimal values.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.