UNPKG

@accounter/server

Version:
67 lines (66 loc) 1.99 kB
/** * Format a number as a string for pgtyped numeric columns * * @param value - Numeric value (number or string) * @returns String representation suitable for pgtyped numeric fields * * @remarks * - pgtyped expects numeric values as strings to preserve precision * - Handles both number and string inputs * - Preserves decimal precision without rounding * - Negative values are supported * * @throws {Error} If value cannot be converted to a valid numeric string * * @example * ```typescript * formatNumeric(100); // '100' * formatNumeric(100.50); // '100.5' * formatNumeric(-42.99); // '-42.99' * formatNumeric('123.45'); // '123.45' * ``` */ export declare function formatNumeric(value: number | string): string; /** * Format money amount as string (convenience wrapper for formatNumeric) * * @param amount - Money amount (typically in cents or smallest currency unit) * @returns String representation suitable for pgtyped * * @example * ```typescript * formatMoney(10050); // '10050' (e.g., $100.50 in cents) * formatMoney(-2599); // '-2599' (e.g., -$25.99 in cents) * ``` */ export declare function formatMoney(amount: number | string): string; /** * Convert decimal amount to string preserving precision * * @param amount - Decimal amount * @param decimals - Number of decimal places (default: 2) * @returns String with fixed decimal places * * @example * ```typescript * formatDecimal(100.5, 2); // '100.50' * formatDecimal(42.123456, 4); // '42.1235' * formatDecimal(1000, 0); // '1000' * ``` */ export declare function formatDecimal(amount: number, decimals?: number): string; /** * Parse a numeric string back to a number * * @param value - String representation of a number * @returns Parsed number * * @throws {Error} If value cannot be parsed as a number * * @example * ```typescript * parseNumeric('100.50'); // 100.5 * parseNumeric('-42'); // -42 * ``` */ export declare function parseNumeric(value: string): number;