Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decimal to Fraction 2

Status
Not open for further replies.

bkrampe

IS-IT--Management
Nov 30, 2006
77
US
I was wondering if it was possible for CR XI to convert a decimal # to a fraction on its own.
 
This is probably not what you mean, but you could convert a decimal to display as a fraction of 100 by using:

mid(towords({table.decimal}), instr(towords({table.decimal}), "and")+4)

This would return 33/100 for .33, etc.

-LB
 
Crystal can't do it without a formula, the way you can in Excel.

The problem is that crystal never sought this as a priority item to include.

You might try working with the DollarFR() function.

You also might consider writing your own function. That pretty much turns this into a lookup that tries to determine which bracket the number falls inside of.

Here is an example:

Code:
local numbervar numSource:={@SourceNumber};
local numbervar numWhole:=0;
local numbervar numRemainder:=0; 
local stringvar strRemainder;


numWhole:=truncate(numSource);

numRemainder:=numSource-numWhole;

strRemainder:= 
select numRemainder
    Case is < .09375:
        "1/16"
    Case is < .15625:
        "1/8"
    Case is < .21875:
        "3/16"
    Case is < .28125:
        "1/4"
    Case is < .34375:
        "5/16"
    Case is < .40625:
        "3/8"
    Case is < .46875:
        "7/16"
    Case is < .53125:
        "1/2"
    Case is < .59375:
        "9/16"
    Case is < .65625:
        "5/8"
    Case is < .71875:
        "11/16"
    Case is < .78125:
        "3/4"
    Case is < .84375:
        "13/16"
    Case is < .90625:
        "7/8"
    Case is < .96875:
        "15/16"
    default:
        " ";

strRemainder;

You might wonder where I got the numbers. All I did was get excel out, build a set of rows that divided each of the numbers from 1 to 16 using 16 as the denominator. So 1/16, 2/16, etc.

Then I just averaged a given cell with the one above it. So the decimal of 1/16 is .0625 and the decimal of 2/16 is .15625. The average of these is .09375, which takes care of rounding. It is equivalent of 1.5/16

I would probably turn this into a function. And drop the formula onto the canvas, reduce the font.

But that's just one approach.

You could also take the above formula and turn it into two formulas, one for numerator, one for denominator. Then place these on the canvas one above the other with a slash (solidus) or horizontal bar (vinculum) between them.

 
Thanks smcnulty2000 yours would of worked, but the infor that andymc was exactly what i was looking for. Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top