I know that Decimal or a custom class is generally is the preferred way of representing currency, but I am asking if it can be also achieved using integer. If not possible, I would like to know why.
I know we should never use float to represent currency, because of the floating point precision issues:
burger = 1.3
amount = 3
total = burger * amount # 3.9000000000000004
Python have the Decimal module that solves the issue:
from decimal import Decimal
burger = Decimal('1.3')
amount = 3
total = burger * amount # Decimal('3.9')
print(total) # 3.9
But there is also the option to store the values and do the Math operations using integers. If we need to show the value to a human, we just divide by 100 to show the representation as currency:
burger = 130
amount = 3
total = burger * amount # 390
print(total / 100) # 3.9
Using integers seem much simpler, but would the integer solution work in any situation involving currency representation? Is there any trade-offs when using integer to represent currency?