Skip to main content

castToNumber

Cast any input to a rounded number.

Signature

castToNumber(input: any, default?: number): number;

Parameters

NameTypeOptionalDescription
inputanyNoSpecifies the input.
defaultnumberYesOptional parameter which specifies the default number if the supplied input cannot be casted.

Return value

Returns the number value.

Example

import { castToNumber } from "@tripetto/builder";

castToNumber("1"); // Returns `1`
castToNumber("1.5"); // Returns `2`
castToNumber(undefined); // Returns `0`