What is the Math Data Type?

You are currently viewing What is the Math Data Type?

Overview

The data type Math provides constants and static methods for common mathematical functions. 

The data type Math can be used when trying to perform mathematical functions like absolute value, rounding, power, and truncation. 

Math can also be employed when you’re looking to use Pi or the logarithmic base of E.

What can you do with the Math Data Type?

Below are some great examples of the use of Objects:

  • Determine the Aboslute Value of a Number
  • Creating Pi or the Logarithmic base of E
  • Rounding Numerical Values

Commonly Used Properties

The following are some commonly used properties for the Math data type. A property is a characteristic or attribute of an object (i.e. Math). To learn more about properties, click here

Pi - Represents the value of Pi

Example Property Example Return Return Type
Math.Pi
3.14159265358979
Double

E - Represents the natural logarithmic base

Example Property Example Return Return Type
Math.E
2.71828182845904
Double

Commonly Used Methods

The following are some commonly used methods for the Math data type. Methods are actions that objects (i.e. Math) can perform. To learn more about methods, click here

For all examples below, we will be using the following Int32 variable, intVar, which has been assigned as 108.

Abs(*) - Returns the absolute value of a number. *Can be used with Decimal, Double, Integer and Single data types.

Example Method Example Return Return Type
Math.Abs(-45)
45
Same as input
Math.Abs(intVar)
108
Integer (Int32)

Ceiling(Decimal or Double) - Returns the smallest integer greater than or equal to a specified decimal or double.

Example Method Example Return Return Type
Math.Ceiling(45.4)
46
Same as input

Floor(Decimal or Double) - Returns the largest integer greater than or equal to a specified decimal or double.

Example Method Example Return Return Type
Math.Floor(45.4)
45
Same as input

Max(*,*) - Returns the larger of two numbers. *Compatible with all number formats.

Example Method Example Return Return Type
Math.Max(45,22)
45
Same as input
Math.Max(intVar,22)
108
Integer (Int32)

Min(*,*) - Returns the smaller of two numbers. *Compatible with all number formats.

Example Method Example Return Return Type
Math.Min(45,22)
22
Same as input
Math.Min(intVar,22)
22
Integer (Int32)

Pow(Double,Double) - Returns a specified number raised to the specified power.

Example Method Example Return Return Type
Math.Pow(3,2)
9
Double
Math.Pow(2,2)
4
Double

Round(Decimal or Double) - Rounds a decimal or double to the nearest integer.

Example Method Example Return Return Type
Math.Round(45.6)
46
Same as Input

Round(Decimal or Double,Integer) - Rounds a decimal or double to the nearest integer with a specified number of decimal places.

Example Method Example Return Return Type
Math.Round(45.66,1)
45.7
Same as Input
Math.Round(45.66,0)
46
Same as Input

Sign(Integer) - Returns an integer that indicates the sign of a number. Returns -1 for negative, 0 for 0 or 1 if positive.

Example Method Example Return Return Type
Math.Sign(45)
1
Integer (Int32)
Math.Sign(-45)
-1
Integer (Int32)
Math.Sign(0)
0
Integer(Int32)
Math.Sign(intVar)
1
Integer(Int32)

Truncate(Decimal or Double) - Rounds a Decimal or Double to the nearest integer aiming towards 0.

Example Method Example Return Return Type
Math.Truncate(45.6)
45
Same as Input