# Bitcoin values store in int64?

I need to store and perform calculations on values with 8 (0.00000001) decimal places.
Could i use double for this?

What’s the max value (left side of decimal) for doubles?

I have tried using int64 but i can’t get them to text like so:

``ToText( Myint64BTC / RatedBTC ) As string``

I looked at this but cant seem to understand it.

Numerical limits
The maximum value of a double is: ±1.79769313486231570814527423731704357e+308
The minimum value towards zero is: ±4.94065645841246544176568792868221372e-324

I need to know the absolute values. Without e-324 or e+308.

Double should work. For the text conversion, use Str or Cstr.

``dim s as String = str(n,"0.0#######")``

That will give you up to 8 decimal places.

[quote=221590:@Greg O’Lone]Double should work. For the text conversion, use Str or Cstr.

``dim s as String = str(n,"0.0#######")``

That will give you up to 8 decimal places.[/quote]

That’s what i needed.

You have the figures, so far as the powers go; but, I have never heard of a double that can display more than 17 or 18 digits. Yes, it can hold a positive number to the power of 308, but that number will have only 17 or 18 digits tops. If it can hold the number of digits shown in the XOJO help page then it is something that I have never seen in my 50+ years of programming. If someone can point me to documentation that shows otherwise I would be happy to read it.

Xojo’s double can represent 16 to 17 significent digits max, Omikron basic ( for Atari ST) had a 10-byte float variable type called REAL10 that could show 19 significent digits. Delphi has also a 10-byte float (called Extended i think) that is also the basis for their currency variable type.

…or store them as Satoshis (or uBtc’s even) using uInt64.
You should avoid using floating point arithmetic for anything that has to do with currency. Always do calculations and comparisons using fixed-point arithmetic.
See here for some basic pitfalls: link

[quote=221721:@Marco Hof]…or store them as Satoshis (or uBtc’s even) using uInt64.
You should avoid using floating point arithmetic for anything that has to do with currency. Always do calculations and comparisons using fixed-point arithmetic.
See here for some basic pitfalls: link [/quote]

That’s what i was trying to do. But i can’t seem to do calculations and return a string.

Like so: ToText( SomeInt64 / SomeOtherInt64 )
But i seemed to get it using Str( Calc / Calc2, “0.0#######” )

I’m not sure if I understand you question. You mean displaying formatted?

For currencies, my preferred way is doing all the storing and arithmetic in (u)Int64. The units depends on how precise you want to be. You shouldn’t use floats/doubles for that.
The way how to display things doesn’t matter. As long as it’s correct and makes sense.

So in case of Bitcoin maybe something like this.

``````Dim Satoshi As uInt64

// 1 BTC in Satoshis
Satoshi = 100000000

// Do some math with it
Satoshi = Satoshi + ((Satoshi / 100) * 13)

// Display as BTC with 8 decimals
System.DebugLog(Format(Satoshi / 1e8,  "###,##0.00000000"))

// Or with 2
System.DebugLog(Format(Satoshi / 1e8,  "###,##0.00"))``````

1 problem. String is not available in iOS so i can’t handle them correctly now.

[quote=221927:@Marco Hof]I’m not sure if I understand you question. You mean displaying formatted?

For currencies, my preferred way is doing all the storing and arithmetic in (u)Int64. The units depends on how precise you want to be. You shouldn’t use floats/doubles for that.
The way how to display things doesn’t matter. As long as it’s correct and makes sense.

So in case of Bitcoin maybe something like this.

[code]
Dim Satoshi As uInt64

// 1 BTC in Satoshis
Satoshi = 100000000

// Do some math with it
Satoshi = Satoshi + ((Satoshi / 100) * 13)

// Display as BTC with 8 decimals
System.DebugLog(Format(Satoshi / 1e8, “###,##0.00000000”))

// Or with 2
System.DebugLog(Format(Satoshi / 1e8, “###,##0.00”))
[/code][/quote]

Thanks, i’ll try this. As it’s probably better than what i’m using now.

```dim Calc as double = rnd*1000 dim Calc2 as double = rnd*10 Str( Calc / Calc2, "0.0#######" )```

iOS :

``` Dim calc As Double = RandomInt(0, 1000)+(RandomInt(0, 1000)/1000) Dim calc2 As Double = RandomInt(0, 10) Dim n as Double = calc/calc2 Dim t As Text = n.ToText(Locale.Current, "0.0#######") system.debuglog t```

I used random for calc and calc2 just for the sake of having something to compute.