Convert Number to Fraction

0 pts.
Tags:
C
RPG
Anyone know an easy way in RPG to convert a decimal number to a fraction. For example I want take 1.75 and convert it to 1 3/4. Any suggestions would be appreciated. Thank, Tim
ASKED: March 30, 2005  1:48 PM
UPDATED: April 1, 2005  11:56 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

If you’re looking for ‘easy’ the easiest way would to create a compile time array that has your fraction values.
Do a look up (using your decimal value) to reference your corresponding ‘fraction’ value, plug it in and away you go.
I only recommend this approach if you have a limited number / range of fractions. . . I’d say down to 10ths.

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Nevster
    I'd agree with the array as being the simplest form but if its going to be a larger number of entries ie. more than a hundred, say, I'd opt for a file or sql table.
    0 pointsBadges:
    report
  • Tdsinc
    I would also use an array but would limit entries to the fractions anticipated. You need only enter the decimal in the array. Example: .03125
    0 pointsBadges:
    report
  • JonP
    Before one can determine the "best" method it would be really useful to know what the smallest unit you intend to use is. Are you really going to be trying to represent fractions such as 11/1112ths? If not what is the smallest unit? 32nds - 64ths? or does it vary by product or ........
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following