Extracting Fractions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In Access code, how do I extract fraction from a double value?

E.g. I want to extract 0.16 from 29.16.
I also want to extract 0.16 from -29.16 Any ideas?
 
Charles said:
In Access code, how do I extract fraction from a double value?

E.g. I want to extract 0.16 from 29.16.
I also want to extract 0.16 from -29.16 Any ideas?

What does "extract" mean? Do you want 29 as a result or 0.16?

For the former...
Fix(DoubleValue)

For the Latter...
DoubleValue - Fix(DoubleValue)
 
I want 0.16 as the result. Thanks for help.

Rick Brandt said:
What does "extract" mean? Do you want 29 as a result or 0.16?

For the former...
Fix(DoubleValue)

For the Latter...
DoubleValue - Fix(DoubleValue)
 
Charles said:
In Access code, how do I extract fraction from a double value?

E.g. I want to extract 0.16 from 29.16.
I also want to extract 0.16 from -29.16 Any ideas?
If you don't want to do a calculation because of rounding, you can do this.

dim dblFraction as Double
dblFraction = GetFraction( someDoubleNumber)

Function GetFraction(dblWholeNumber As Double) As Double
Dim str1 As String
Dim str2 As String
Dim num1 As Double
Dim num2 As Double
Dim x As Integer

str1 = CStr(dblWholeNumber)
x = InStr(1, str1, ".")
str2 = Mid(str1, x, (Len(str1) + 1) - x)
GetFraction = CDbl(str2)
End Function

Ron
 
Back
Top