I'm about to convert the initial value to string
Yes! (but don't do it by calling str
- use a string literal)
and do the math with string manipulations
No!
When hardcoding a decimal value into your source code, you should initialize it from a string literal, not a float literal. With 4321.90
, floating-point rounding has already occurred, and building a Decimal won't undo that. With "4321.90"
, Decimal has the original text you wrote available to perform an exact initialization:
Decimal('4321.90')