KyberSwap Docs
Search
K

Percent

Enables the safe handling of percentages.
GitHub File: percent.ts

Extends

Properties

Public

Property
Type
Modifier
Description
isPercent
true
readonly
Boolean if the Percent instance is a percentage value. Prevents fractions from being interpreted as a Percent.

Constructor

Percent instances are derived from the Fraction class via the toPercent() function which takes a Fraction and converts it into a Percent. For each of the algorithmic methods in the Percent class, the toPercent() function is called after the Fraction calculations are completed.

Methods

add()

Adds the provided fraction to the Percent instance and returns the result as a new Percent.

Parameters

Params
Type
Description
other
Fraction | BigintIsh
The fraction to be added to the underlying Fraction value of the Percent instance.

Returns

Type
Description
Percent
The Percent value representing the sum of the two fractions.

subtract()

Subtracts/minuses the provided fraction to the Percent instance and returns the result as a new Percent.

Parameters

Params
Type
Description
other
Fraction | BigintIsh
The fraction to be subtracted from the underlying Fraction value of the Percent instance.

Returns

Type
Description
Percent
The Percent after subtracting the given fraction from the underlying Fraction.

multiply()

Multiplies the Percent instance with the provided fraction and returns the result as a new Percent.

Parameters

Params
Type
Description
other
Fraction | BigintIsh
The fraction to be multiplied with the underlying Fraction value of the Percent instance.

Returns

Type
Description
Percent
The Percent value after multiplying the given fraction with the underlying Fraction.

divide()

Divides the Percent instance with the provided fraction and returns the result as a new Percent.

Parameters

Params
Type
Description
other
Fraction | BigintIsh
The fraction to be divided from the underlying Fraction value of the Percent instance.

Returns

Type
Description
Fraction
The Percent value after dividing the underlying Fraction by the provided fraction.

toSignificant()

Rounds the Percent to the significant digits specified.

Parameters

Params
Type
Description
significantDigits
number
The number of significant digits to round to. Default is 5.
format
object
Configure output format per toformat specifications. Optional.
rounding
Rounding
Specifies the rounding logic used. Default is ROUND_HALF_UP which rounds to the nearest neighbour and rounds up if equidistant.

Returns

Type
Description
string
The final Percent value rounded to the specified significant digits.

toFixed()

Rounds the Percent to the fixed number of decimals specified.

Parameters

Params
Type
Description
decimalPlaces
number
The number of decimal places to round to. Default is 2.
format
object
Configure output format per toformat specifications.
rounding
Rounding
Specifies the rounding logic used. Default is ROUND_HALF_UP which rounds to the nearest neighbour and rounds up if equidistant.

Returns

Type
Description
string
The final Percent value rounded to the decimal places specified.
Last modified 4mo ago