4 ms·
Money should be represented in the base unit, for dollars that is cents. So for your sum fields it should be sum_in_base_units = 859 not 8.59. Decimal can los
by cryowaffle 12y ago
Money should be represented in the base unit, for dollars that is cents. So for your sum fields it should be sum_in_base_units = 859 not 8.59. Decimal can lose accuracy as you move around systems, it's most safe to just use base units.
- drdaeman 12y ago> Decimal can lose accuracy as you move around systems Could you please provide an example? Given that Decimals are simplistically represented as a tuple (sign, digits, exponent), I don't see how it's less accurate than an int.
- vertex-four 12y agoSimplest one: open up Python, enter: ((.1)*3)/3 It should come up as 0.10000000000000002. I honestly don't understand the reason, though.
- detaro 12y agoThese are normal floats, not Decimals, which are Python's exact floating point type.
- wldcordeiro 12y agoYou're thinking of floats which are different than the Decimal type[1]. https://docs.python.org/3/library/decimal.html?highlight=decimal#module-decimal https://docs.python.org/3/library/decimal.html?highlight=dec...