Python‎ > ‎decimal‎ > ‎

Decimal.copy_sign()


Definition
Copy_sign(other, context=None) - Return a copy of the first operand with the sign set to be the same as the sign of the second operand.

Syntax
Decimal.copy_sign(x)

Parameters
x=Decimal

Examples
The return is:
 >>> Decimal(1.3).copy_sign(Decimal(1.3))
Decimal('1.3000000000000000444089209850
062616169452667236328125')
>>>

list.append(decimal)
The method list the decimal value and limit the decimal point to '1.00' through quantize.
from decimal import Decimal
list1=list()
list.append((Decimal(2.10).copy_negate().quantize(Decimal('1.00')),
                                 Decimal(1.3).copy_sign(Decimal(1.3)).quantize(Decimal('1.00')),
                                    Decimal(3).exp().quantize(Decimal('1.00')))
)
print("The items in the list1 are:,", list1)

>>> 
The items in the list1 are:, [(Decimal('-2.10'), Decimal('1.30'), Decimal('20.09'))]
>>>


Comments