Why does this code output 25 although I used the decimal module. I tried it on the calculator and it outputted 26.28.
from decimal import *
getcontext().prec = 2
targetPrice = 40
currentPrice = 56.5
winChance = 0.9
stopLoss = 23
lossChance = 0.1
expectancy =100 * abs(((Decimal(targetPrice) - Decimal(currentPrice)) / Decimal( currentPrice))) * Decimal(winChance)
print(expectancy)
Decimal()to floating-point values entirely misses the point of the Decimal module. 0.9, for example, is not a value that can be accurately represented as a float; turning it into a Decimal results in a precise value that isn't quite equal to 0.9. You have to use strings -Decimal('0.9')for example - to produce exact values.