Skip to main content

round_dp_python

Function round_dp_python 

Source
pub fn round_dp_python(number: Decimal, dp: u32) -> Decimal
Expand description

Round to dp decimal places with Python decimal’s sign rule for zero.

Python’s quantize keeps the sign when a small negative rounds away:

  Decimal("-0.00495").quantize(Decimal("0.01"))  ==  -0.00
  Decimal("-0.0000001").quantize(Decimal("0.01")) == -0.00

rust_decimal’s round_dp returns an UNSIGNED zero there, which loses the only information the cell still carries — that the underlying balance is negative rather than exactly zero. bean-query renders -0.00 USD for a -0.00495 USD position; rledger rendered 0.00 USD and read as flat.

The result is padded to exactly dp (see the caller’s note on round_dp only ever reducing the scale).