'------------------------------------------------------
'How To: Find Numbers to right of decimal point
'Posted: 19 August 1998
'From: VISBAS-L
'Description: Three different solutions were posted for
'this question and I thought they might be useful to you
'since these are common problems you may face.
'------------------------------------------------------
Q:How can I take a number stored in a double and figure out
just the decimal part of it? I.E., get .35 from 6.35?
A:I combined the answers into a quick project;
start a new VB project and add three labels then
add the following code.
Private Sub Form_Load()
'Example #1 Fred Lyhne - jflyhne@SALTSPRING.COM
Dim a#, b#
a = 6.65123456
b = a - Int(a)
Label1.Caption = Format(b, ".#########")
'Example #2 Lemmox Heel - jamyr@INTERGATE.BC.CA
'-----------------------------------------------------
'This example manipulates the number as a string
'rather than as a double. To see how this value can be
'converted from one type to another look at example #4
'-----------------------------------------------------
Dim MyNum As String
MyNum = a
DecimalPlace = InStr(MyNum, ".")
RightOfDecimal = Mid(MyNum, DecimalPlace, Len(MyNum))
Label2.Caption = RightOfDecimal
'Example #3 Mike George - wycliffe@MINDSPRING.COM
dDouble = 6.65123456
dDouble = dDouble - Fix(dDouble)
Label3.Caption = dDouble
Label3.Caption = Format(dDouble, ".#########")
'Example #4 Richard J. Doyle - rdoyle29@MSN.COM
Dim str As String
Dim intDecPos As Integer
Dim dbl As Double
dbl = 6.65123456
str = CStr(dbl)
intDecPos = InStr(1, str, ".")
str = Right(str, Len(str) - intDecPos + 1)
dbl = CDbl(str)
Label4.Caption = str
End Sub
Downloads
In IE right-click and select 'Save Target As...' or in Netscape
right-click and select 'Save Link As...'
View Plain Text
Not Available
Not Available