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
  • X
  • Bluesky
  • GitHub
  • Forum
Js Module
Overview
Js
submodules
  • Array
  • Array2
  • BigInt
  • Blob
  • Console
  • Date
  • Dict
  • Exn
  • File
  • Float
  • Global
  • Int
    • v
      toExponential
    • v
      toExponentialWithPrecision
    • v
      toPrecision
    • v
      toPrecisionWithPrecision
    • v
      toString
    • v
      toStringWithRadix
    • v
      toFloat
    • v
      equal
    • v
      max
    • v
      min
  • Json
    • Kind
  • List
  • Map
  • Math
  • Null
  • Null_undefined
  • Nullable
  • Obj
  • Option
  • Promise
  • Promise2
  • Re
  • Result
  • Set
  • String
  • String2
  • TypedArray2
    • DataView
    • Float64Array
    • Float32Array
    • Uint32Array
    • Int32Array
    • Uint16Array
    • Int16Array
    • Uint8ClampedArray
    • Uint8Array
    • Int8Array
    • ArrayBuffer
    Typed_array
    • DataView
    • Float64_array
    • Float64Array
    • Float32_array
    • Float32Array
    • Uint32Array
    • Int32_array
    • Int32Array
    • Uint16Array
    • Int16Array
    • Uint8ClampedArray
    • Uint8Array
    • Int8Array
    • S
    • ArrayBuffer
    • Type
  • Types
  • Undefined
  • Vector
  • WeakMap
  • WeakSet
  • API / Js / Int

    Int

    Provide utilities for handling int.

    toExponential

    RESCRIPT
    let toExponential: int => string

    Formats an int using exponential (scientific) notation. Returns a string representing the given value in exponential notation. Raises RangeError if digits is not in the range [0, 20] (inclusive).

    See toExponential on MDN.

    Examples

    RESCRIPT
    /* prints "7.7e+1" */ Js.log(Js.Int.toExponential(77))

    toExponentialWithPrecision

    RESCRIPT
    let toExponentialWithPrecision: (int, ~digits: int) => string

    Formats an int using exponential (scientific) notation. digits specifies how many digits should appear after the decimal point. The value must be in the range [0, 20] (inclusive).

    Returns a string representing the given value in exponential notation.

    The output will be rounded or padded with zeroes if necessary. Raises RangeError if digits is not in the range [0, 20] (inclusive).

    See toExponential on MDN.

    Examples

    RESCRIPT
    /* prints "7.70e+1" */ Js.log(Js.Int.toExponentialWithPrecision(77, ~digits=2)) /* prints "5.68e+3" */ Js.log(Js.Int.toExponentialWithPrecision(5678, ~digits=2))

    toPrecision

    RESCRIPT
    let toPrecision: int => string

    Formats an int using some fairly arbitrary rules. Returns a string representing the given value in fixed-point (usually).

    toPrecision differs from toFixed in that the former will format the number with full precision, while the latter will not output any digits after the decimal point. Raises RangeError if digits is not in the range accepted by this function.

    See toPrecision on MDN.

    Examples

    RESCRIPT
    /* prints "123456789" */ Js.log(Js.Int.toPrecision(123456789))

    toPrecisionWithPrecision

    RESCRIPT
    let toPrecisionWithPrecision: (int, ~digits: int) => string

    Formats an int using some fairly arbitrary rules. digits specifies how many digits should appear in total. The value must between 0 and some arbitrary number that's hopefully at least larger than 20 (for Node it's 21. Why? Who knows).

    Returns a string representing the given value in fixed-point or scientific notation.

    The output will be rounded or padded with zeroes if necessary.

    toPrecisionWithPrecision differs from toFixedWithPrecision in that the former will count all digits against the precision, while the latter will count only the digits after the decimal point. toPrecisionWithPrecision will also use scientific notation if the specified precision is less than the number of digits before the decimal point. Raises RangeError if digits is not in the range accepted by this function.

    See toPrecision on MDN.

    Examples

    RESCRIPT
    /* prints "1.2e+8" */ Js.log(Js.Int.toPrecisionWithPrecision(123456789, ~digits=2)) /* prints "0.0" */ Js.log(Js.Int.toPrecisionWithPrecision(0, ~digits=2))

    toString

    RESCRIPT
    let toString: int => string

    Formats an int as a string. Returns a string representing the given value in fixed-point (usually).

    See toString on MDN.

    Examples

    RESCRIPT
    /* prints "123456789" */ Js.log(Js.Int.toString(123456789))

    toStringWithRadix

    RESCRIPT
    let toStringWithRadix: (int, ~radix: int) => string

    Formats an int as a string. radix specifies the radix base to use for the formatted number. The value must be in the range [2, 36] (inclusive). Returns a string representing the given value in fixed-point (usually). Raises RangeError if radix is not in the range [2, 36] (inclusive).

    See toString on MDN.

    Examples

    RESCRIPT
    /* prints "110" */ Js.log(Js.Int.toStringWithRadix(6, ~radix=2)) /* prints "deadbeef" */ Js.log(Js.Int.toStringWithRadix(3735928559, ~radix=16)) /* prints "2n9c" */ Js.log(Js.Int.toStringWithRadix(123456, ~radix=36))

    toFloat

    RESCRIPT
    let toFloat: int => float

    equal

    RESCRIPT
    let equal: (int, int) => bool

    max

    RESCRIPT
    let max: int

    min

    RESCRIPT
    let min: int
    Types and values
    • v
      toExponential
    • v
      toExponentialWithPrecision
    • v
      toPrecision
    • v
      toPrecisionWithPrecision
    • v
      toString
    • v
      toStringWithRadix
    • v
      toFloat
    • v
      equal
    • v
      max
    • v
      min

    © 2025 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on