Creates a new Decimal instance from a float but rounding using self as the context. >>> context = Context(prec=5, rounding=ROUND_DOWN) >>> context.create_decimal_from_float(3.1415926535897932) Decimal('3.1415') >>> context = Context(prec=5, traps=[Inexact])
(self, f)
| 4090 | return d._fix(self) |
| 4091 | |
| 4092 | def create_decimal_from_float(self, f): |
| 4093 | """Creates a new Decimal instance from a float but rounding using self |
| 4094 | as the context. |
| 4095 | |
| 4096 | >>> context = Context(prec=5, rounding=ROUND_DOWN) |
| 4097 | >>> context.create_decimal_from_float(3.1415926535897932) |
| 4098 | Decimal('3.1415') |
| 4099 | >>> context = Context(prec=5, traps=[Inexact]) |
| 4100 | >>> context.create_decimal_from_float(3.1415926535897932) |
| 4101 | Traceback (most recent call last): |
| 4102 | ... |
| 4103 | decimal.Inexact: None |
| 4104 | |
| 4105 | """ |
| 4106 | d = Decimal.from_float(f) # An exact conversion |
| 4107 | return d._fix(self) # Apply the context rounding |
| 4108 | |
| 4109 | # Methods |
| 4110 | def abs(self, a): |