Open hugohills-regnosys opened 2 months ago
Hi Hugo, this looks great and we think it'll be enough for DRR requeriments. I don't see in which cases applying RoundToPrecision(10)&RoundToSignificantFigures(11) in sequence makes a difference than just appliying the later, specifically for DRR. Could you clarify if you found any edge case? Thanks!
Background
Currently the CDM supports rounding functionality in functions
cdm.base.math.RoundToPrecision
(see https://github.com/finos/common-domain-model/issues/2915) andcdm.base.math.RoundToNearest
, however this does not cover the use-case for rounding to a number of significant figures.This particular use-case for this is from DRR where prices that are expressed as percentages are required to be reported in the format: “up to 11 numeric characters including up to 10 decimals if price is expressed as percentage”.
Proposal
Add function
cdm.base.math.RoundToSignificantFigures
. For the DRR use-case, the price should be rounded by theRoundToPrecision
function (with precision = 10), then rounded by theRoundToSignificantFigures
function (with significant figures = 11).The following examples show the function behaviour:
RoundToSignificantFigures(1023.123456789, 5, RoundingDirectionEnum -> NEAREST)
RoundToSignificantFigures(1023.123456789, 5, RoundingDirectionEnum -> UP)
RoundToSignificantFigures(1023.123456789, 5, RoundingDirectionEnum -> DOWN)
RoundToSignificantFigures(1023.123456789, 1, RoundingDirectionEnum -> NEAREST)
RoundToSignificantFigures(1023.1, 7, RoundingDirectionEnum -> NEAREST)
Compatibility
This would be a new function, so there would be no compatibility issues.