Reducing precision of numeric values?

If I have a Decimal, what’s the best way to convert it to a Numeric 2 ?

  1. fromNumeric (roundCommercial 2 d)
  2. roundToNumeric RoundingDown (fromNumeric d)
  3. castAndRound d
  4. cast d

Option 4 is listed for completeness but one should not use it as it fails if d has more than 2 decimal places). Is option 1 performing a conversion to BigNumeric under the hood or similar to 3? Option 1, gives you more control over the rounding (one could roundBankers), but not nearly as many options as the RoundingMode utilized by 2.

1 Like

Option 1 does not go via BigDecimal. If the rounding modes are sufficient, that’s probably what I’d chose since it’s reasonably explicit about what you want to do and fairly efficient.

Option 2 for when you need all the rounding modes.

3 for when you don’t care about being explicit wtr to rounding. Option 4 for when you don’t need rounding.

2 Likes