Repository navigation
test: Replace satoshi_round with int() or Decimal() - #23210
Conversation
satoshi_round will round down. To make the code easier to parse use Decimal() where possible, which does not round. Or use int(), which explicitly rounds down.
|
If the problem is Decimal is very nice, no surprise |
|
Um sorry I thought satoshi_round had an optional argument |
You know this, but it is "Decimal(str) where possible, which When Decimal(1) is fed a float, machine-specific witchcraft is |
I don't think the argument should be optional, but required, so that the caller explicitly specifies whether to round down or up. Though, it seems unrelated to the changes here. I am happy to review a follow-up pr. |
If I were to do it right now, I would actually raise TypeError immediately |
|
I agree, but I think it is unrelated to the changes here. |
I think satoshi_round should only round down, that is its defining behaviour. If you have 1.5*10^-8 BTC, you have 1 satoshi, you never have 2. Perhaps it should just be renamed to satoshi_truncate though. |
|
I'd say it depends on the value you pass. If it is a fee, you want to round up (See #22949). If it is a value, you want to round down. |
satoshi_round will round down. To make the code easier to parse use
Decimal() where possible, which does not round. Or use int(), which
explicitly rounds down.