Float

This module includes convenience methods for handling float types.

-

RESCRIPT
let -: (float, float) => float

Subtraction of two float values. Can be opened in a module to avoid dot-notation (-.), however this yields a shadow warning (Warning number 44) in the default configuration.

Examples

RESCRIPT
open Belt.Float 2.0 - 1.0 == 1.0

*

RESCRIPT
let *: (float, float) => float

Multiplication of two float values. Can be opened in a module to avoid dot-notation (*.), however this yields a shadow warning (Warning number 44) in the default configuration.

Examples

RESCRIPT
open Belt.Float 2.0 * 2.0 == 4.0

/

RESCRIPT
let /: (float, float) => float

Division of two float values. Can be opened in a module to avoid dot-notation (/.), however this yields a shadow warning (Warning number 44) in the default configuration.

Examples

RESCRIPT
open Belt.Float 4.0 / 2.0 == 2.0

+

RESCRIPT
let +: (float, float) => float

Addition of two float values. Can be opened in a module to avoid dot-notation (+.), however this yields a shadow warning (Warning number 44) in the default configuration.

Examples

RESCRIPT
open Belt.Float 2.0 + 2.0 == 4.0

fromInt

RESCRIPT
let fromInt: int => float

Converts a given int to a float.

Examples

RESCRIPT
Belt.Float.fromInt(1) == 1.0

fromString

RESCRIPT
let fromString: string => option<float>

Converts a given string to a float. Returns Some(float) when the input is a number, None otherwise.

Examples

RESCRIPT
Belt.Float.fromString("1.0") == Some(1.0)

toInt

RESCRIPT
let toInt: float => int

Converts a given float to an int.

Examples

RESCRIPT
Belt.Float.toInt(1.0) == 1

toString

RESCRIPT
let toString: float => string

Converts a given float to a string. Uses the JavaScript String constructor under the hood.

Examples

RESCRIPT
Belt.Float.toString(1.0) == "1"