Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-181

Specify the maximum of digits when parsing a Fraction

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Labels:
      None

      Description

      Firstly, thanks for the Fraction code - I've adapated it for something I'm working on and I didn't have a clue how to convert a decimal to a fraction

      Excel spreadsheets have the facility to specify a fraction format where you specify the maximum number of denominator digits to display.

      So for example:
      format "?/?" displays decimal values formatted in the range 1/2 to n/9
      format "/" displays decimal values formatted in the range 1/2 to n/99
      format "?/?" displays decimal values formatted in the range 1/2 to n/999 etc

      In excel then the value 0.6152 displays as 3/5, 8/13 and 510/829 respectively for the above 3 formats.

      I'm attaching a patch for the Fraction class which adds a new constructor where the maximum number of digits can be specified, rather than the epsilon value.

        Attachments

        1. MATH-181-FractionMaxDenominator.patch
          4 kB
          Niall Pemberton
        2. MATH-181-FractionDigitsLimit-v2.patch
          5 kB
          Niall Pemberton
        3. MATH-181-FractionDigitsLimit.patch
          5 kB
          Niall Pemberton

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              niallp Niall Pemberton
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: