Learn R Programming

LifeInsureR (version 1.0.1)

RoundingHelper: Helper object to define rounding rules for the InsuranceContract, InsuranceTarif and ProfitParticipation classes.

Description

The class RoundingHelper provides the code and settings to define numeric rounding rules for premiums, reserves, benefits etc. of a life insurance contract. By default, no rounding it applied.

Arguments

Public fields

rounding

The (named) list containing all declared rounding definitions

Methods


Method new()

Initialize the rounding settings

Usage

RoundingHelper$new(...)

Arguments

...

named entries specifying rounding accuracy

Details

Sets up the rounding helper by giving a list of named entries, specifying rounding accuracy for each particular value

Examples

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$round("raw", c(1234.567891, 0.00012345, 1234))
rounding$round("hundred", c(1234.567891, 0.00012345, 1234))
rounding$round("accurate", c(1234.567891, 0.00012345, 1234))
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))


Method round()

Round the given values using the pre-defined accuracy

Usage

RoundingHelper$round(spec, value, ...)

Arguments

spec

the ID used for looking up the desired accuracy

value

the values to be rounded according to 'spec'

...

currently unused

Details

Rounds the given values using the accuracies defined in the internal rounding list (set either via the 'initialize' function or via a call to 'setRounding'. The accuracies are defined using a 'spec' identifier, which allows to define different accuracies for different uses

Examples

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$round("raw", c(1234.567891, 0.00012345, 1234))
rounding$round("hundred", c(1234.567891, 0.00012345, 1234))
rounding$round("accurate", c(1234.567891, 0.00012345, 1234))
# If the given spec does not exist, no rounding it applied
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))


Method setRounding()

Define rounding accuracy for a certain identifier

Usage

RoundingHelper$setRounding(key, spec, ...)

Arguments

key

the ID used for looking up the desired accuracy

spec

the rounding accuracy (number of digits)

...

currently unused

Details

Configures the rounding helper for a given named entry, specifying rounding accuracy for each particular value

Examples

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$round("raw", c(1234.567891, 0.00012345, 1234))
rounding$round("hundred", c(1234.567891, 0.00012345, 1234))
rounding$round("accurate", c(1234.567891, 0.00012345, 1234))
# If the given spec does not exist, no rounding it applied
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))
# Add a new spec with different settings:
rounding$setRounding("non-existing", 1)
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))


Method getRounding()

Extract rounding accuracy for a certain identifier

Usage

RoundingHelper$getRounding(key, ...)

Arguments

key

the ID used for looking up the desired accuracy

...

currently unused

Details

Read out the rounding for a given named entry.

Examples

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$getRounding("hundred")


Method clone()

The objects of this class are cloneable with this method.

Usage

RoundingHelper$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

Run this code
# TODO

## ------------------------------------------------
## Method `RoundingHelper$new`
## ------------------------------------------------

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$round("raw", c(1234.567891, 0.00012345, 1234))
rounding$round("hundred", c(1234.567891, 0.00012345, 1234))
rounding$round("accurate", c(1234.567891, 0.00012345, 1234))
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))

## ------------------------------------------------
## Method `RoundingHelper$round`
## ------------------------------------------------

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$round("raw", c(1234.567891, 0.00012345, 1234))
rounding$round("hundred", c(1234.567891, 0.00012345, 1234))
rounding$round("accurate", c(1234.567891, 0.00012345, 1234))
# If the given spec does not exist, no rounding it applied
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))

## ------------------------------------------------
## Method `RoundingHelper$setRounding`
## ------------------------------------------------

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$round("raw", c(1234.567891, 0.00012345, 1234))
rounding$round("hundred", c(1234.567891, 0.00012345, 1234))
rounding$round("accurate", c(1234.567891, 0.00012345, 1234))
# If the given spec does not exist, no rounding it applied
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))
# Add a new spec with different settings:
rounding$setRounding("non-existing", 1)
rounding$round("non-existing", c(1234.567891, 0.00012345, 1234))

## ------------------------------------------------
## Method `RoundingHelper$getRounding`
## ------------------------------------------------

rounding = RoundingHelper$new(raw = 0, hundred = -2, accurate = 4)
rounding$getRounding("hundred")

Run the code above in your browser using DataLab