API / Belt / Float

You are currently looking at the v6.0 - v8.2 docs (Reason v3.6 syntax edition). You can find the latest API docs here.

(These docs cover all versions between v3 to v8 and are equivalent to the old BuckleScript docs before the rebrand)

Float

This module includes convenience methods for handling float types.

toInt

RE
let toInt: float => int;

Converts a given float to an int.

RE
Js.log(Belt.Float.toInt(1.0) === 1); /* true */

fromInt

RE
let fromInt: int => float;

Converts a given int to a float.

RE
Js.log(Belt.Float.fromInt(1) === 1.0); /* true */

fromString

RE
let fromString: string => option(float);

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

RE
Js.log(Belt.Float.fromString("1.0") === Some(1.0)); /* true */

toString

RE
let toString: float => string;

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

RE
Js.log(Belt.Float.toString(1.0) === "1.0"); /* true */

+

RE
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.

RE
open Belt.Float; Js.log(2.0 + 2.0 === 4.0); /* true */

-

RE
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.

RE
open Belt.Float; Js.log(2.0 - 1.0 === 1.0); /* true */

*

RE
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.

RE
open Belt.Float; Js.log(2.0 * 2.0 === 4.0); /* true */

/

RE
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.

RE
open Belt.Float; Js.log(4.0 / 2.0 === 2.0); /* true */