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
  • Twitter
  • GitHub
  • Forum
Core Module
Overview
Core
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • v
      equal
    • v
      compare
    • v
      toExponential
    • v
      toExponentialWithPrecision
      D
    • v
      toFixed
    • v
      toFixedWithPrecision
      D
    • v
      toPrecision
    • v
      toPrecisionWithPrecision
      D
    • v
      toString
    • v
      toStringWithRadix
      D
    • v
      toLocaleString
    • v
      toFloat
    • v
      fromFloat
    • v
      fromString
    • v
      mod
    • t
      rangeOptions
    • v
      range
    • v
      rangeWithOptions
      D
    • v
      clamp
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • Internal
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
  • List
  • Map
  • MapperRt
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Promise
  • Re
    • Result
    RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • API / Core / Int

    Int

    Functions for interacting with JavaScript Number. See: Number.

    equal

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

    compare

    RESCRIPT
    let compare: (int, int) => Core__Ordering.t

    toExponential

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

    toExponential(n, ~digits=?) return a string representing the given value in exponential notation. digits specifies how many digits should appear after the decimal point. See Number.toExponential

    Examples

    RESCRIPT
    Int.toExponential(1000) // "1e+3" Int.toExponential(-1000) // "-1e+3" Int.toExponential(77, ~digits=2) // "7.70e+1" Int.toExponential(5678, ~digits=2) // "5.68e+3"

    Exceptions

    • RangeError: If digits less than 0 or greater than 10.

    toExponentialWithPrecision

    Deprecated

    Use toExponential instead

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

    toExponential(n, ~digits) return a string representing the given value in exponential notation. digits specifies how many digits should appear after the decimal point. See Number.toExponential on MDN.

    Examples

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

    Exceptions

    • RangeError: If digits less than 0 or greater than 10.

    toFixed

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

    toFixed(n, ~digits=?) return a string representing the given value using fixed-point notation. digits specifies how many digits should appear after the decimal point. See Number.toFixed on MDN.

    Examples

    RESCRIPT
    Int.toFixed(123456) // "123456.00" Int.toFixed(10) // "10.00" Int.toFixed(300, ~digits=4) // "300.0000" Int.toFixed(300, ~digits=1) // "300.0"

    Exceptions

    • RangeError: If digits is less than 0 or larger than 100.

    toFixedWithPrecision

    Deprecated

    Use toFixed instead

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

    toFixedWithPrecision(n, ~digits) return a string representing the given value using fixed-point notation. digits specifies how many digits should appear after the decimal point. See Number.toFixed on MDN.

    Examples

    RESCRIPT
    Int.toFixedWithPrecision(300, ~digits=4) // "300.0000" Int.toFixedWithPrecision(300, ~digits=1) // "300.0"

    Exceptions

    • RangeError: If digits is less than 0 or larger than 100.

    toPrecision

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

    toPrecision(n, ~digits=?) return a string representing the giver value with precision. digits specifies the number of significant digits. See Number.toPrecision on MDN.

    Examples

    RESCRIPT
    Int.toPrecision(100) // "100" Int.toPrecision(1) // "1" Int.toPrecision(100, ~digits=2) // "1.0e+2" Int.toPrecision(1, ~digits=2) // "1.0"

    Exceptions

    • RangeError: If digits is not between 1 and 100 (inclusive). Implementations are allowed to support larger and smaller values as well. ECMA-262 only requires a precision of up to 21 significant digits.

    toPrecisionWithPrecision

    Deprecated

    Use toPrecision instead

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

    toPrecisionWithPrecision(n, ~digits) return a string representing the giver value with precision. digits specifies the number of significant digits. See Number.toPrecision on MDN.

    Examples

    RESCRIPT
    Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2" Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0"

    Exceptions

    • RangeError: If digits is not between 1 and 100 (inclusive). Implementations are allowed to support larger and smaller values as well. ECMA-262 only requires a precision of up to 21 significant digits.

    toString

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

    toString(n, ~radix=?) return a string representing the given value. ~radix specifies the radix base to use for the formatted number. See Number.toString on MDN.

    Examples

    RESCRIPT
    Int.toString(1000) // "1000" Int.toString(-1000) // "-1000" Int.toString(6, ~radix=2) // "110" Int.toString(373592855, ~radix=16) // "16449317" Int.toString(123456, ~radix=36) // "2n9c"

    Exceptions

    RangeError: if radix is less than 2 or greater than 36.

    toStringWithRadix

    Deprecated

    Use toString instead

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

    toStringWithRadix(n, ~radix) return a string representing the given value. ~radix specifies the radix base to use for the formatted number. See Number.toString on MDN.

    Examples

    RESCRIPT
    Int.toStringWithRadix(6, ~radix=2) // "110" Int.toStringWithRadix(373592855, ~radix=16) // "16449317" Int.toStringWithRadix(123456, ~radix=36) // "2n9c"

    Exceptions

    RangeError: if radix is less than 2 or greater than 36.

    toLocaleString

    RESCRIPT
    let toLocaleString: int => string

    toLocaleString(n) return a string with language-sensitive representing the given value. See Number.toLocaleString on MDN.

    Examples

    RESCRIPT
    // If the application uses English as the default language Int.toLocaleString(1000) // "1,000" // If the application uses Portuguese Brazil as the default language Int.toLocaleString(1000) // "1.000"

    toFloat

    RESCRIPT
    let toFloat: int => float

    toFloat(n) return a float representing the given value.

    Examples

    RESCRIPT
    Int.toFloat(100) == 100.0 Int.toFloat(2) == 2.0

    fromFloat

    RESCRIPT
    let fromFloat: float => int

    fromFloat(n) return an int representing the given value. The conversion is done by truncating the decimal part.

    Examples

    RESCRIPT
    Int.fromFloat(2.0) == 2 Int.fromFloat(1.999) == 1 Int.fromFloat(1.5) == 1 Int.fromFloat(0.9999) == 0

    fromString

    RESCRIPT
    let fromString: (string, ~radix: int=?) => option<int>

    fromString(str, ~radix=?) return an option<int> representing the given value str. ~radix specifies the radix base to use for the formatted number.

    Examples

    RESCRIPT
    Int.fromString("0") == Some(0) Int.fromString("NaN") == None Int.fromString("6", ~radix=2) == None

    mod

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

    mod(n1, n2) calculates the modulo (remainder after division) of two integers.

    Examples

    RESCRIPT
    Int.mod(7, 4) == 3

    rangeOptions

    RESCRIPT
    type rangeOptions = {step?: int, inclusive?: bool}

    The options for range.

    range

    RESCRIPT
    let range: (int, int, ~options: rangeOptions=?) => array<int>

    range(start, end, ~options=?) returns an int array of the sequence of integers in the range [start, end). That is, including start but excluding end.

    If step is not set and start < end, the sequence will be increasing in steps of 1.

    If step is not set and start > end, the sequence will be decreasing in steps of -1.

    If step is set, the sequence will increase or decrease by that amount for each step. If start < end and step is negative, or vice versa, an empty array is returned since the sequence would otherwise never reach or exceed the end value and hence be infinite. If step is 0 and start != end, a RangeError is raised as the sequence would never reach or exceed the end value and hence be infinite.

    If inclusive is set to true, the sequence will include end if step is set such that the sequence includes it.

    Examples

    RESCRIPT
    Int.range(3, 6) == [3, 4, 5] Int.range(-3, -1) == [-3, -2] Int.range(3, 1) == [3, 2] Int.range(3, 7, ~options={step: 2}) == [3, 5] Int.range(3, 7, ~options={step: 2, inclusive: true}) == [3, 5, 7] Int.range(3, 6, ~options={step: -2}) // RangeError

    Exceptions

    • Raises RangeError if step == 0 && start != end.

    rangeWithOptions

    Deprecated

    Use range instead

    RESCRIPT
    let rangeWithOptions: (int, int, rangeOptions) => array<int>

    rangeWithOptions(start, end, options) is like range, but with step and inclusive options configurable.

    If step is set, the sequence will increase or decrease by that amount for each step. If start < end and step is negative, or vice versa, an empty array is returned since the sequence would otherwise never reach or exceed the end value and hence be infinite. If step is 0 and start != end, a RangeError is raised as the sequence would never reach or exceed the end value and hence be infinite.

    If inclusive is set to true, the sequence will include end if step is set such that the sequence includes it.

    Examples

    RESCRIPT
    Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5] Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7] Int.rangeWithOptions(3, 6, {step: -2}) // RangeError

    Exceptions

    • Raises RangeError if step == 0 && start != end.

    clamp

    RESCRIPT
    let clamp: (~min: int=?, ~max: int=?, int) => int

    clamp(~min=?, ~max=?, value) returns value, optionally bounded by min and max.

    if max < min returns min.

    Examples

    RESCRIPT
    Int.clamp(42) == 42 Int.clamp(42, ~min=50) == 50 Int.clamp(42, ~max=40) == 40 Int.clamp(42, ~min=50, ~max=40) == 50
    Types and values
    • v
      equal
    • v
      compare
    • v
      toExponential
    • v
      toExponentialWithPrecision
      D
    • v
      toFixed
    • v
      toFixedWithPrecision
      D
    • v
      toPrecision
    • v
      toPrecisionWithPrecision
      D
    • v
      toString
    • v
      toStringWithRadix
      D
    • v
      toLocaleString
    • v
      toFloat
    • v
      fromFloat
    • v
      fromString
    • v
      mod
    • t
      rangeOptions
    • v
      range
    • v
      rangeWithOptions
      D
    • v
      clamp

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on