Skip to main content

index/functions/decimalRoundingUp.md

decimalRoundingUp(value, decimals): BigNumber

Round decimal up to specified precision (ceiling rounding)

Always rounds UP to the specified decimal places. This ensures system accuracy and prevents shortchanging calculations (e.g., fee calculations always round up to protect the fee recipient).

Consolidates 3 occurrences of Math.ceil with decimal precision patterns.

Parameters​

ParameterTypeDescription
valuestring | number | BigNumberValue to round (string, number, or BigNumber)
decimalsnumberNumber of decimal places to preserve

Returns​

BigNumber

Rounded value as BigNumber

Throws​

Error if decimals is negative

Example​

// Fee calculations that always round up
const fee = decimalRoundingUp('1.234', 2); // 1.24 (rounds up from 1.23)

// Preserve more decimals
const precise = decimalRoundingUp('1.23456', 4); // 1.2346

// Integer rounding
const integer = decimalRoundingUp('1.1', 0); // 2 (rounds up to next integer)

// Very small values
const tiny = decimalRoundingUp('0.00001', 4); // 0.0001