1

I am trying to use UDF in xlwings and I want to achieve required precision as both libraries Python Decimal and mpmath allows for this. I am calculating 2 ^ 0.5 with following functions:

@xw.func
def fce_2(x, y):
    import decimal
    from decimal import Decimal
    decimal.getcontext().prec = 100
    z = Decimal(x)** Decimal(y)
      
    return z

This returns 1,4142

AND

@xw.func
def fce_1(x, y):
    from mpmath import mp
    mp.dps = 100
    z = mp.mpf(x)** mp.mpf(y)
      
    return z

Returns 1,414213562 None of them returns the required number of decimal places which should be 100.

Skip
  • 21
  • 1

1 Answers1

0

Numbers in Excel cells are always stored as 64 bit double floats, having about 15 significant digits. It should be possible to display more digits as string, use return str(z).

Redoute
  • 208
  • 1
  • 8