import { type MapFunction } from '../value/map'; import { type Maybe } from '../value/maybe.type'; import { type AsNumberInput } from './number'; export type FloorOrCeilRounding = 'floor' | 'ceil'; export type NumberRounding = 'none' | FloorOrCeilRounding | 'round'; export type RoundingFunction = MapFunction; /** * Returns a rounding function for the specified rounding type. * * @param type - The rounding strategy: 'floor', 'ceil', 'round', or 'none' * @returns The corresponding Math function, or an identity function for 'none' */ export declare function roundingFunction(type: NumberRounding): RoundingFunction; export type RoundingInput = NumberRounding | RoundingFunction; /** * The number of decimal places ot use. */ export type NumberPrecision = number; /** * Truncates a number (or number string) to the specified decimal precision without rounding. * * Accepts strings and null/undefined via {@link asNumber}. * * @param input - Number, number string, or null/undefined * @param precision - Number of decimal places to retain * @returns The truncated number value */ export declare function cutValueToPrecision(input: AsNumberInput, precision: NumberPrecision): number; /** * Cuts the value to zero precision. */ export declare const CUT_VALUE_TO_ZERO_PRECISION: CutValueToPrecisionFunction; /** * Truncates a value to an integer by cutting to zero decimal precision. * * @param input - Number, number string, or null/undefined * @returns The truncated integer value */ export declare function cutValueToInteger(input: AsNumberInput): number; /** * Rounds the input using cutToPrecision */ export type CutValueToPrecisionFunction = ((input: AsNumberInput) => number) & { readonly _precision: number; }; /** * Creates a {@link CutValueToPrecisionFunction} that truncates values to the configured precision. * * @param precision - Number of decimal places to retain * @param roundingType - Rounding strategy; defaults to 'cut' (truncation) * @returns A function that accepts a number or string and returns the truncated number */ export declare function cutValueToPrecisionFunction(precision: NumberPrecision, roundingType?: RoundToPrecisionFunctionType): CutValueToPrecisionFunction; /** * Rounds the input number to the given precision using a configured rounding function. * * @param value * @param precision * @returns */ export type RoundToPrecisionFunction = MapFunction; export type RoundToPrecisionFunctionType = NumberRounding | 'cut'; /** * Creates a function that rounds numbers to the specified precision using a configurable rounding strategy. * * @param precision - Number of decimal places * @param roundFn - Rounding strategy; defaults to 'round'. Use 'cut' for truncation. * @returns A function that rounds numbers to the configured precision */ export declare function roundToPrecisionFunction(precision: NumberPrecision, roundFn?: RoundToPrecisionFunctionType): RoundToPrecisionFunction; /** * Rounds a number to the specified decimal precision using `Math.round`. * * @param value - Number to round * @param precision - Number of decimal places to retain * @returns The rounded number */ export declare function roundToPrecision(value: number, precision: NumberPrecision): number; /** * Truncates a number to the specified decimal precision without rounding. * * Uses `Math.floor` for positive numbers and `Math.ceil` for negative numbers to truncate toward zero. * For example, 1.25 with precision 1 becomes 1.2 (not 1.3). * * @param value - Number to truncate * @param precision - Number of decimal places to retain * @returns The truncated number */ export declare function cutToPrecision(value: number, precision: NumberPrecision): number; /** * Number used to increase or decrease by the "step" value. When used in rounding the steps are aligned at a StepOrigin. */ export type StepNumber = number; /** * Origin value for StepNumbers that is used as an offset for input. Is usually 0. */ export type StepOrigin = number; /** * Rounds a number up to the nearest multiple of the step size using `Math.ceil`. * * @param value - Input value * @param step - Step size to round up to * @returns The nearest multiple of step that is >= value */ export declare function roundNumberUpToStep(value: number, step: number): number; /** * roundNumberToStepFunction() */ export interface RoundNumberToStepFunctionConfig { step: StepNumber; /** * Type of rounding to use. */ round: Omit; /** * Offset to apply to each input number. Defaults to zero. */ origin?: StepOrigin; } export type RoundNumberToStepFunctionInput = RoundNumberToStepFunctionConfig | StepNumber; /** * Rounds the number to a specific "step" that contains it. * * For example, with the value of 2, and a step size of 5, and rounding using ceil, the value will be rounded up to 1. * * @param value Input value. * @returns Step that contains the value. */ export type RoundNumberToStepFunction = ((input: Maybe) => number) & { readonly _round: RoundNumberToStepFunctionConfig; }; /** * Creates a function that rounds numbers to the nearest step multiple using a configurable rounding strategy. * * Accepts either a step number (uses 'ceil' rounding) or a full config with step, rounding type, and origin. * * @param input - Step size or full configuration * @returns A function that rounds input numbers to the nearest step * @throws Error if step is 0 or undefined */ export declare function roundNumberToStepFunction(input: RoundNumberToStepFunctionInput): RoundNumberToStepFunction;