Lines Matching refs:Decimal
471 PEP 327: Decimal Data Type
478 accurately. The new :class:`Decimal` type can represent these fractions
482 Why is Decimal needed?
533 Hence, the :class:`Decimal` type was created.
536 The :class:`Decimal` type
540 contains two classes, :class:`Decimal` and :class:`Context`. :class:`Decimal`
544 :class:`Decimal` instances are immutable, like regular Python integers and FP
546 represents. :class:`Decimal` instances can be created from integers or
550 >>> decimal.Decimal(1972)
551 Decimal("1972")
552 >>> decimal.Decimal("1.1")
553 Decimal("1.1")
558 >>> decimal.Decimal((1, (1, 4, 7, 5), -2))
559 Decimal("-14.75")
569 string to the :class:`Decimal` constructor::
572 >>> decimal.Decimal(str(f))
573 Decimal("1.1")
574 >>> decimal.Decimal('%.12f' % f)
575 Decimal("1.100000000000")
577 Once you have :class:`Decimal` instances, you can perform the usual mathematical
581 >>> a = decimal.Decimal('35.72')
582 >>> b = decimal.Decimal('1.73')
584 Decimal("37.45")
586 Decimal("33.99")
588 Decimal("61.7956")
590 Decimal("20.64739884393063583815028902")
592 Decimal("1275.9184")
598 You can combine :class:`Decimal` instances with integers, but not with
602 Decimal("39.72")
606 TypeError: You can interact Decimal only with int, long or Decimal data types.
609 :class:`Decimal` numbers can be used with the :mod:`math` and :mod:`cmath`
613 and not a :class:`Decimal`. ::
616 >>> d = decimal.Decimal('123456789012.345')
622 :class:`Decimal` instances have a :meth:`sqrt` method that returns a
623 :class:`Decimal`, but if you need other things such as trigonometric functions
627 Decimal("351364.1828820134592177245001")
654 >>> decimal.Decimal(1) / decimal.Decimal(7)
655 Decimal("0.1428571428571428571428571429")
657 >>> decimal.Decimal(1) / decimal.Decimal(7)
658 Decimal("0.142857143")
664 >>> decimal.Decimal(1) / decimal.Decimal(0)
669 >>> decimal.Decimal(1) / decimal.Decimal(0)
670 Decimal("Infinity")
682 :pep:`327` - Decimal Data Type