castToNumber
Cast any input to a rounded number.
Signature
castToNumber(input: any, default?: number): number;
Parameters
Name | Type | Optional | Description |
---|---|---|---|
input | any | No | Specifies the input. |
default | number | Yes | Optional 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`