huge fractions from string to number

[quote=405488:@Alberto De Poo]

Dim n, d, x As Decimal DecSetPrecision(40) DecSetScale(39) n = New Decimal( "156348578434374084375" ) d = New Decimal( "147573952589676412928" ) x = n / d MsgBox Str(x)[/quote]

D’oh! In my test I was assigning the Decimals from integer literals (slaps forehead). Thanks.

If your final result is going to be type double, then the precision is limited to about 16 significant digits. Knowing that, you can simply truncate the numerator and denominator of your fraction to about 17 digits (to allow for round off) which will fit in int64s, then divide these two values.

Function BigFracToDouble(bigFrac As String) as Double dim nd() As String = split(ReplaceAll(bigFrac," ",""),"/") dim nTrunc As String = left(nd(0),17) dim dTrunc As String = left(nd(1),17) dim pwr As Integer = (len(nd(0))-len(nTrunc))-(len(nd(1))-len(dTrunc)) return nTrunc.Val/dTrunc.Val*10^pwr End Function
This produces a result of 1.059459177522304e+0 which agrees with the BigFloat result to the precision limit of type double.