numerica
    Preparing search index...

    Function toFraction

    • Converts a decimal number to its simplified fraction representation.

      Parameters

      • n: number

        The decimal number to convert to a fraction

      • options: Options = {}

        Configuration options

        • mixed

          Display as a mixed number (default: false)

        • pretty

          Use Unicode fraction slash (⁄) (default: false)

        • symbol

          Custom fraction symbol (default: "/" or "⁄" if pretty)

        • space

          Space character between whole and fractional parts (default: " ")

      Returns string

      The fraction as a string

      toFraction(0.5)                    // "1/2"
      toFraction(2.5) // "5/2"
      toFraction(2.5, {mixed: true}) // "2 1/2"
      toFraction(0.75, {pretty: true}) // "3⁄4"
      toFraction(0.333) // "333/1000"
      toFraction(-1.25, {mixed: true}) // "-1 1/4"