Is floating point arbitrary precision available?

后端 未结 5 1301
梦毁少年i
梦毁少年i 2020-11-22 09:11

Just for fun and because it was really easy, I\'ve written a short program to generate Grafting numbers, but because of floating point precision issues it\'s not finding som

5条回答
  •  渐次进展
    2020-11-22 09:27

    use decimal, (here is a clearer example):

    >>> 2.3-2.2
    0.09999999999999964
    >>> from decimal import Decimal
    >>> Decimal('2.3')-Decimal('2.2')
    Decimal('0.1')
    >>> float(Decimal('2.3')-Decimal('2.2'))
    0.1
    >>> 
    

提交回复
热议问题