I am a new user to Crystal (6 months) and I use it to create reports for a cabinet making program called CabinetVision. I recently have been struggling with what should be a simple task which is to convert a decimal generated number into a fraction.
With the help of this forum (myself 10% the forum 90%) I've gotten a decimal to fraction conversion formula up and running---sort of.
The problem is that it is not rounding properly. The program I am using (see above) is generating decimals numbers that round themselves to the closest 1/16
Ex: 1/16 = .0625 or
Ex: 1/8 = .1250
The decimal to fraction conversion formula is not something I prepared; I downloaded it from Business Objects' knowledge base.
Here are the fractions I want to generate side by side with the actual fractions generated by the conversion formula:
What I want What I'm getting
0 0/2 (?)
1/16 3/50
1/8 13/100
3/16 19/100
1/4 1/4
5/16 31/100
3/8 19/50
7/16 11/25
1/2 1/2
and so on
I feel like I'm so close; This is a very important formula for me to get running, any and all help is always appreciated---Thanks
Here is the formula: Note: {@DECIMAL} is my internal formula that generates the decimal number that needs to be converted
into a fraction
__________________________
__________
__________
__________
__________
__________
__________
__________
_____
' This formula uses Basic syntax.
'Note: {@DECIMAL} is my internal formula that generates the decimal number that needs to be converted into a fraction
Evaluateafter ({@DECIMAL})
Dim decInput as number
Dim decimalFraction as number
Dim numerator as number
Dim denominator as number
Dim wholeNumber as number
' This variable will hold the value to be converted
' to a fraction type value.
Dim testNum as number
' The number 1.75 will be converted to look like
' 1 3/4 as a string output.
testNum = {@DECIMAL}
wholeNumber = int(testNum)
' In CR 8.5 this line would be
' decInput = round(testNum - wholeNumber,2)
decInput = round(testNum - wholeNumber,2)
numerator = 1
denominator = 1
decimalFraction = numerator / denominator
do While (decimalFraction <> decInput)
If (decimalFraction < decInput) Then
numerator = numerator + 1
Else
denominator = denominator + 1
numerator = truncate(decInput * denominator)
End If
decimalFraction = numerator / denominator
loop
formula = totext(wholeNumber,0,"") + " " + totext(numerator,0 , "") & "/" & totext(denominator,0 , "")
Start Free Trial