TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Language: Visual Basic
Expertise: Beginner
Sep 28, 1999

### WEBINAR:On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

# Mathmatical Functions: Decimals

Question:
How can I read only from one side of the decimal in VB6? I need to get .4286 from a value of 22.4286. I also need to know how to get the integer value of 108.75 to read 108 and not round up to 109. Please help, I am lost.

There are two functions in VB to return the integer value of the number. These are Int and Fix. The difference between the two is that if the number you are using is negative, Int returns the first Integer value that is less than, or equal to, your number. Fix on the other hand returns the first negative integer greater than, or equal to, the number.

Both Int and Fix return the same values for positive numbers, the first integer value less than, or equal to, the number you pass.

There is no intrinsic function within VB to return the decimal portion of a number. The best you can do is create a function to do this for you. The easiest would just be to look for a decimal point and return anything after it like the following:

```Private Function Dec(Number As Double) As Double
Dim pos As Long

pos = InStr(1, Number, ".")
If pos > 0 Then
Dec = Val(Mid(Number, pos))
Else
Dec = 0.0
End If

End Function
```
DevX Pro

 Submit a Tip Browse "Application Design" Tips Browse All Tips
Comment and Contribute

(Maximum characters: 1200). You have 1200 characters left.

Thanks for your registration, follow us on our social networks to keep up-to-date