Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>CInt</code> does a whole lot more than <a href="https://msdn.microsoft.com/en-us/library/b3h1hf19(v=vs.110).aspx?cs-save-lang=1&amp;cs-lang=vb" rel="nofollow noreferrer"><code>Integer.Parse</code></a>.</p> <p><code>CInt</code> will first check to see if what it was passed is an integer, and then simply casts it and returns it. If it's a double it will try to convert it without first converting the double to a string.</p> <p>See this from the help for <code>CInt</code> and other <a href="http://msdn.microsoft.com/en-us/library/s2dy91zy.aspx" rel="nofollow noreferrer">Type Conversion Functions</a></p> <blockquote> <p>Fractional Parts. When you convert a nonintegral value to an integral type, the integer conversion functions (CByte, CInt, CLng, CSByte, CShort, CUInt, CULng, and CUShort) remove the fractional part and round the value to the closest integer.</p> <p>If the fractional part is exactly 0.5, the integer conversion functions round it to the nearest even integer. For example, 0.5 rounds to 0, and 1.5 and 2.5 both round to 2. This is sometimes called banker's rounding, and its purpose is to compensate for a bias that could accumulate when adding many such numbers together.</p> </blockquote> <p>So in short, it does much more than convert a string to an integer, e.g. applying specific rounding rules to fractions, short circuting unecessary conversions etc.</p> <p>If what you're doing is converting a string to an integer, use <a href="https://msdn.microsoft.com/en-us/library/b3h1hf19(v=vs.110).aspx?cs-save-lang=1&amp;cs-lang=vb" rel="nofollow noreferrer"><code>Integer.Parse</code></a> (or <a href="https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx" rel="nofollow noreferrer"><code>Integer.TryParse</code></a>), if you're coercing an unknown value (e.g. a <code>variant</code> or <code>object</code> from a database) to an integer, use <code>CInt</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload