rescale method

PgDecimal rescale(
  1. int scale, [
  2. PgRoundingMode mode = PgRoundingMode.halfAwayFromZero
])

O valor com exatamente scale dígitos depois da vírgula (ver round).

Implementation

PgDecimal rescale(int scale,
    [PgRoundingMode mode = PgRoundingMode.halfAwayFromZero]) {
  if (_kind != _finite) return this;
  if (scale >= _scale) {
    return PgDecimal._finiteValue(_upscale(_unscaled, _scale, scale), scale);
  }
  final rounded = _divRound(_unscaled, _pow10(_scale - scale), mode);
  if (scale >= 0) return PgDecimal._finiteValue(rounded, scale);
  return PgDecimal._finiteValue(rounded * _pow10(-scale), 0);
}