Mathmatical Functions: Decimals

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.

Answer:
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 IfEnd Function
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of