lanka-validations - v2.1.0
    Preparing search index...

    Function validateLKRDecimal

    • Parses a decimal string into exact cents. Numbers are intentionally rejected because they may already have lost decimal precision.

      Parameters

      • input: unknown

        Amount as a decimal string. Numbers are rejected because they may already have lost precision.

      • options: LkrDecimalOptions = {}

        Optional allowNegative, excessDecimals ('reject', 'round', 'truncate'), and maxMinorUnits.

      Returns ValidationResult<LkrMinorUnitAmount>

      { isValid: true, data } with { minorUnits, decimal }, or { isValid: false, error, errors, code }.

      validateLKRDecimal('1,250.50').isValid; // true
      validateLKRDecimal('1.005').code; // 'CURRENCY_EXCESS_DECIMALS'