Field as Fraction, not decimal

  • Thread starter Thread starter JenP
  • Start date Start date
J

JenP

Hi there -
How would I get a field in a query to output a result as
a fraction instead of a decimal?

I am building in Design view, not SQL.

Thanks!
Jenni
 
JenP said:
How would I get a field in a query to output a result as
a fraction instead of a decimal?

I am building in Design view, not SQL.


You'll have to create a function to derive an approximate
fraction from a numeric value.

Here's one I had laying around to get you started:

Public Function CvFraction(x As Double) As String
Dim dblQ As Double
Dim B As Long

For B = 2 To 16
dblQ = x * B
If Abs(Sgn(x) * (Int(Abs(dblQ) + 2 ^ -8) / B) - x) <
2 ^ -7 Then
CvFraction = CInt(dblQ) & "/" & B
Exit For
End If
Next B

If B = 17 Then CvFraction = CStr(x)

End Function
 
Back
Top