Math

Lack of native support for fixed point math in Solidity created the need for workarounds using integers.

Working with Percentage Values

Percentage values are represented using integers with extra digits for decimals. There are constants in the contract to help convert percentage values when interacting with it:

PERCENT_DECIMALS - how many decimal digits do the percent values in the contract have.

ONE_HUNDRED_PERCENT - a value representing 100% in the context of the contract.

For example:

Using PERCENT_DECIMALS value of 2, 100% is represented as 10000, and 30.05% is represented as 3005.

By default, Sapling smart contracts use 6 decimals for percentage values for the added precision.

Last updated