Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • X
  • BlueSky
  • GitHub
  • Forum
Belt Stdlib
Overview
  • Introduction
Basics
  • Array
  • List
  • Float
  • Int
    • -
    • *
    • /
    • +
    • fromFloat
    • fromString
    • toFloat
    • toString
  • Range
  • Id
  • Option
  • Result
Set
  • HashSet
  • HashSetInt
  • HashSetString
  • Set
  • SetDict
  • SetInt
  • SetString
Map
  • HashMap
  • HashMapInt
  • HashMapString
  • Map
  • MapDict
  • MapInt
  • MapString
Mutable Collections
  • MutableMap
  • MutableMapInt
  • MutableMapString
  • MutableQueue
  • MutableSet
  • MutableSetInt
  • MutableSetString
  • MutableStack
Sort Collections
  • SortArray
  • SortArrayInt
  • SortArrayString
Utilities
  • Debug
API / Belt / Int

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)

Int

This module includes convenience methods for handling int types.

toFloat

RE
let toFloat: int => float;

Converts a given int to a float.

RE
Js.log(Belt.Int.toFloat(1) === 1.0); /* true */

fromFloat

RE
let fromFloat: float => int;

Converts a given float to an int.

RE
Js.log(Belt.Int.fromFloat(1.0) === 1); /* true */

fromString

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

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

RE
Js.log(Belt.Int.fromString("1") === Some(1)); /* true */

toString

RE
let toString: int => string;

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

RE
Js.log(Belt.Int.toString(1) === "1"); /* true */

+

RE
let (+): (int, int) => int;

Addition of two int values. Same as the addition from Pervasives.

RE
open Belt.Int; Js.log(2 + 2 === 4); /* true */

-

RE
let (-): (int, int) => int;

Subtraction of two int values. Same as the subtraction from Pervasives.

RE
open Belt.Int; Js.log(2 - 1 === 1); /* true */

*

RE
let ( * ): (int, int) => int;

Multiplication of two int values. Same as the multiplication from Pervasives.

RE
open Belt.Int; Js.log(2 * 2 === 4); /* true */

/

RE
let (/): (int, int) => int;

Division of two int values. Same as the division from Pervasives.

RE
open Belt.Int; Js.log(4 / 2 === 2); /* true */

© 2024 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on