Convert.ToInteger(Convert)
Converts data to an integer.
Applies To
Description
Converts data to an integer. This converts data types into integers. Not all objects will return a non-zero integer when converting.
-
Text: any text that resembles an integer will resolve into an integer. If the text contains non-numeric characters (including decimal points--periods), then the text will be converted to zero.
-
Decimals: converting a decimal number to an integer will truncate the decimal portion off of the number. This will not round, but will simply remove the decimal point and all numbers to the right of the decimal point.
-
Booleans: true resolves to one, and false resolves to zero.
-
Arrays, and Objects: will evaluate to zero.
-
Sales and Purchase Order Numbers: cannot be converted to Integers, even though they are integer numbers. They are too large for integer data type. Instead you must use Convert.ToDecimal(Convert).
Note: If you are converting from a decimal number to an integer, it may be better to use Math.Truncate(Value).
Properties and Methods
None
Available
The .ToInteger(Convert) method is available in:
-
15.03.016
-
All newer builds
Type
Int32
Syntax
Convert.ToInteger(Convert);
Parameters
|
Parameter |
Required |
Description |
|---|---|---|
| Convert | Yes | Any data type and value that converts to an integer |
Example
Event.Form.MessageBox('Text: ' + Convert.ToInteger('25') +
'\nText with a decimal in it: ' + Convert.ToInteger('1.23') +
'\nNon-numeric text: ' + Convert.ToInteger('Hello') +
'\nDecimal: ' + Convert.ToInteger(12.52) +
'\nDateTime: ' + Convert.ToInteger(DateTime.Now) +
'\nBoolean: ' + Convert.ToInteger(true) +
'\nArray: ' + Convert.ToInteger([1, 2, 3]) +
'\nObject: ' + Convert.ToInteger({}));
/*Expected System Prompt Display
Text: 25
Text with a decimal in it: 0
Non-numeric text: 0
Decimal: 12
DateTime: 0
Boolean: 1
Array: 0
Object: 0
*/