Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

 

'------------------------------------------------------
'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 View Plain Text
Download Demo Project Not Available
View Code Online Not Available





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.