{"version":3,"file":"math.cjs","sources":["../src/math.ts"],"sourcesContent":["import { Decimal } from 'decimal.js';\n\ntype CalculableValue = Decimal.Value | { toString: () => string };\n\n/**\n * Options for configuring the output of `toPercentageString`.\n */\nexport interface ToPercentageStringOptions {\n    /**\n     * Number of decimal places to include in the result.\n     * @default 2\n     */\n    decimalPlaces?: number;\n\n    /**\n     * Whether to include the '%' symbol in the result.\n     * @default true\n     */\n    withSymbol?: boolean;\n}\n\n/**\n * Converts a fraction (numerator / denominator) into a percentage string.\n *\n * - Uses `decimal.js` for precise decimal calculations.\n * - Supports custom decimal places and optional percentage symbol.\n * - Returns `'0.00%'` if result is `NaN` or division is invalid.\n *\n * @param {CalculableValue} molecular - The numerator of the fraction.\n * @param {CalculableValue} denominator - The denominator of the fraction.\n * @param {ToPercentageStringOptions} [options] - Optional output settings.\n * @returns {string} Formatted percentage string.\n *\n * @example\n * ```typescript\n * import { toPercentageString } from '@kikiutils/node/math';\n *\n * console.log(toPercentageString(50, 200)); // 25.00%\n * console.log(toPercentageString(50, 200, { withSymbol: false })); // 25.00\n * console.log(toPercentageString(50, 200, { decimalPlaces: 1 })); // 25.0%\n * ```\n */\nexport function toPercentageString(\n    molecular: CalculableValue,\n    denominator: CalculableValue,\n    options?: ToPercentageStringOptions,\n) {\n    const molecularDecimal = new Decimal(molecular.toString());\n    const denominatorDecimal = new Decimal(denominator.toString());\n    const calculationResult = molecularDecimal.div(denominatorDecimal);\n    const result = calculationResult.isNaN()\n        ? '0.00'\n        : calculationResult.times(100).toFixed(options?.decimalPlaces ?? 2);\n\n    return options?.withSymbol ?? true ? `${result}%` : result;\n}\n"],"names":["Decimal"],"mappings":";;;;AAqBA;;;;;;;;;;;;;;;;;;;;AAoBG;SACa,kBAAkB,CAC9B,SAA0B,EAC1B,WAA4B,EAC5B,OAAmC,EAAA;IAEnC,MAAM,gBAAgB,GAAG,IAAIA,kBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC1D,MAAM,kBAAkB,GAAG,IAAIA,kBAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC9D,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAClE,IAAA,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK;AAClC,UAAE;AACF,UAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,IAAI,CAAC,CAAC;AAEvE,IAAA,OAAO,OAAO,EAAE,UAAU,IAAI,IAAI,GAAG,CAAA,EAAG,MAAM,CAAG,CAAA,CAAA,GAAG,MAAM;AAC9D;;;;"}