Skip to main content

castToFloat

Cast any input to a floating point number.

Signature

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

Parameters

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

Return value

Returns the floating point number value.

Example

import { castToFloat } from "tripetto-runner-foundation";

castToFloat("1"); // Returns `1`
castToFloat("1.5"); // Returns `1.5`
castToFloat(undefined); // Returns `0`