This is the latest docs version
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
  • Community
  • X
  • Bluesky
  • GitHub
  • Forum
Belt Module
Overview
Belt
submodules
  • Array
  • Float
  • HashMap
    • String
    • Int
    HashSet
    • String
    • Int
    Id
    • MakeHashable
    • MakeHashableU
    • MakeComparable
    • MakeComparableU
  • Int
    • v
      toFloat
    • v
      fromFloat
    • v
      fromString
    • v
      toString
    • v
      +
    • v
      -
    • v
      *
    • v
      /
  • List
  • Map
    • Dict
    • String
    • Int
    MutableMap
    • String
    • Int
  • MutableQueue
  • MutableSet
    • String
    • Int
  • MutableStack
  • Option
  • Range
  • Result
  • Set
    • Dict
    • String
    • Int
    SortArray
    • String
    • Int
    API / Belt / Int

    Int

    This module includes convenience methods for handling int types.

    toFloat

    RESCRIPT
    let toFloat: int => float

    Converts a given int to a float.

    Examples

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

    fromFloat

    RESCRIPT
    let fromFloat: float => int

    Converts a given float to an int.

    Examples

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

    fromString

    RESCRIPT
    let fromString: string => option<int>

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

    Examples

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

    toString

    RESCRIPT
    let toString: int => string

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

    Examples

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

    +

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

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

    Examples

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

    -

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

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

    Examples

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

    *

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

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

    Examples

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

    /

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

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

    Examples

    RESCRIPT
    open Belt.Int Js.log(4 / 2 === 2); /* true */
    Types and values
    • v
      toFloat
    • v
      fromFloat
    • v
      fromString
    • v
      toString
    • v
      +
    • v
      -
    • v
      *
    • v
      /

    © 2025 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on