Python‎ > ‎decimal‎ > ‎

Decimal.canonical()


Introduction
The function returns with value defaults in python.

Syntax
Decimal(x).canonical()

Parameters
x=Decimal floating point
canonical() takes no arguments

Examples
The return is:
 >> Decimal(-122.00).canonical()
Decimal('-122')

>>> Decimal(22).canonical()
Decimal('22')

>>> Decimal(0.142857).canonical()
Decimal('0.1428570000000000117523768494
720570743083953857421875')

input(Decimal(a).canonical())
The method return decimal values in various decimal methods through input() method.
from decimal import Decimal

print("Python Decimal Methods")
a=Decimal(input("Enter Decimal Value: "))

print("Your value in Decimal().adjusted()) method is: ", Decimal(a).adjusted())

print("---------------------------------------------------------------------------------")
print("While other methods return your value as: ")
print("Your value in Decimal().as_tuple(() method is: ", Decimal(a).as_tuple())

print("---------------------------------------------------------------------------------")
print("Your value in Decimal().canonical() method is: ", Decimal(a).canonical())

print("---------------------------------------------------------------------------------")
print("Your value in Decimal().compare(your value-1) method is: ", Decimal(a).compare(a-1))

print("---------------------------------------------------------------------------------")
print("Your value in Decimal().compare_signal(3)) method is: ", Decimal(a).compare_signal(3))

>>> 
Python Decimal Methods
Enter Decimal Value: 55
Your value in Decimal().adjusted()) method is: 1
---------------------------------------------------------------------------------
While other methods return your value as: 
Your value in Decimal().as_tuple(() method is: DecimalTuple(sign=0, digits=(5, 5), exponent=0)
---------------------------------------------------------------------------------
Your value in Decimal().canonical() method is: 55
---------------------------------------------------------------------------------
Your value in Decimal().compare(your value-1) method is: 1
---------------------------------------------------------------------------------
Your value in Decimal().compare_signal(3)) method is: 1
>>>


set(Decimal)
The return is after pop() the item:
 >>> from decimal import Decimal
>>> a=set()
>>> a.add(Decimal(1).adjusted())
>>> a.add(Decimal(.55).canonical())
>>> a.add(Decimal(-1).compare_signal(1))
>>> a
{0, Decimal('0.5500000000000000444089209850062616169452667236328125'), Decimal('-1')}
>>> b=set()
>>> b.add(Decimal(1).compare_total(2))
>>> b.add(Decimal(0.1).copy_abs())
>>> b
{Decimal('0.1000000000000000055511151231257827021181583404541015625'), Decimal('-1')}
>>> a.pop()
Decimal('-1')
>>> a.union(b)
{Decimal('0.1000000000000000055511151231257827021181583404541015625'), Decimal('-1')}


Comments