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
Belt Module
Overview
Belt
submodules
  • Array
  • Float
    • v
      toInt
    • v
      fromInt
    • v
      fromString
    • v
      toString
    • v
      +
    • v
      -
    • v
      *
    • v
      /
  • HashMap
    • String
    • Int
    HashSet
    • String
    • Int
    Id
    • MakeHashable
    • MakeHashableU
    • MakeComparable
    • MakeComparableU
  • Int
  • 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 / Float

    Float

    This module includes convenience methods for handling float types.

    toInt

    RESCRIPT
    let toInt: float => int

    Converts a given float to an int.

    Examples

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

    fromInt

    RESCRIPT
    let fromInt: int => float

    Converts a given int to a float.

    Examples

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

    fromString

    RESCRIPT
    let fromString: string => option<float>

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

    Examples

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

    toString

    RESCRIPT
    let toString: float => string

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

    Examples

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

    +

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

    Examples

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

    -

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

    Examples

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

    *

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

    Examples

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

    /

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

    Examples

    RESCRIPT
    open Belt.Float Js.log(4.0 / 2.0 === 2.0) /* true */
    Types and values
    • v
      toInt
    • v
      fromInt
    • v
      fromString
    • v
      toString
    • v
      +
    • v
      -
    • v
      *
    • v
      /

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on