Numeric Functions


This lesson takes you through some of the numeric functions in Visual Basic 6. There are several numeric functions as well as math functions in VB6. The Visual Basic language gives you enough power to work with numbers. You can solve many complex problems related to numeric calculations using the numeric functions provided by VB6.

I'm going to explain Sqr, Int and Round functions in this section.


Read the following lesson to learn about more numeric functions:



The Sqr function

The Sqr function returns the square root of a number. This function takes a Double type argument and returns a Double implying that you can work with large numbers using the Sqr function.

Example:
Print Sqr(9)

Output: 3


The Int function

The Int function returns the greatest integer less than or equal to the number. It discards the decimal part of a number. This function greatly helps in truncating the decimal part of a number. But be aware that in case of a negative decimal number, it returns a rounded up value, resulting in an increment of integer part as it's shown in example 3 below.

Example1:
Print Int(2.9)

Output: 2


Example 2:
Print Int(5)

Output: 5


Example 3:
Print Int(-5.8)

Output: -6


The Round function

The Round function rounds a numeric value.

Syntax:
Round(Number, [no. of digits after decimal]

If the second parameter is omitted, the number is rounded to a whole number.

Example:
Print Round(5.8)

Output: 6

Example:
Print Round(5.8, 1)

Output: 5

Example:
Print Round(5.4568, 2)

Output: 5.46


In this lesson, I've not covered all the numeric functions. The other numeric functions are explained in Lesson 47 : Working with numbers.