Skip to main content

castToFloat

Cast any input to a floating point number.

Signature

castToFloat(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 floating point number if the supplied input cannot be casted. |

Return value

Returns the floating point number value.

Example

import { castToFloat } from "@tripetto/runner";

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