Each function can forcibly convert an expression to a specific data type.
Syntax
CBool (expression)
CByte (expression)
CCur (expression)
CDate (expression)
CDbl (expression)
CDec (expression)
CInt (expression)
CLng (expression)
CSng (expression)
CStr (expression)
CVar (expression)
CStr (expression)
The required expression parameter can be any string or numeric expression.
Return type
The function name determines the return type, as shown below:
Function return type expression parameter range
CBool Boolean any valid string or numeric expression.
CByte Byte 0 to 255.
CCur Currency-922,337,203,685,477.5808 to 922,337,203,685,477.5807.
CDate any valid Date expression.
CDbl Double negative number from-1.79769313486232E308 to-4.94065645841247E-324; positive number from 4.94065645841247E-324 to 1.79769313486232E308.
CDec Decimal zero-to-zero ratio value, that is, the number of Decimal places is/-79,228,162,514,264,337,593,543,950,335. For a 28-digit decimal value, the value range is/-7.9228162514264337593543950335. The minimum possible non-zero value is 0.0000000000000000000000000001.
CInt Integer-32,768 to 32,767, rounded to the decimal part.
CLng Long-2,147,483,648 to 2,147,483,647, rounded to the decimal part.
The negative CSng Single number is-3.402823E38 to-1.401298E-45, and the positive number is 1.401298E-45 to 3.402823E38.
CStr String returns Cstr based on the expression parameter.
If CVar Variant is a value, the range is the same as that of Double. If it is not a value, the range is the same as that of String.
Description
If the expression passed to the function exceeds the conversion target data type range, an error occurs. Generally, you can use a data type conversion function during encoding to indicate that the result of some operations should be represented as a specific data type, rather than the default data type. For example, when single-precision, double-precision, or integer operations occur, CCur is used to force the currency operation.
The data type conversion function should be used to replace Val, so that the international version of data conversion can be converted from one data type to another. For example, when Ccur is used, different decimal separator, kilobytes separator, and various currency options are properly identified based on the country settings of the system.
When the decimal part is 0.5, The Cint and CLng functions convert it to the closest even value. For example, 0.5 is converted to 0, and 1.5 is converted to 2. The Cint and CLng functions are different from the Fix and Int functions. The Fix and Int functions truncate the fractional part rather than rounding it. And the Fix and Int functions always return the same value as the input data type.
Use the IsDate function to determine whether a date can be converted to a date or a time. Cdate can be used to identify date text and time text, as well as numbers falling into the acceptable date range. When a number is converted to a date, the integer part is converted to a date, and the decimal part is converted to the time from midnight.
CDate determines the date format based on the country settings on the system. If the format provided is an unrecognized date setting, the order of the year, month, and day cannot be correctly determined. In addition, the long date format cannot be recognized if it contains a string of weeks.
The CVDate function also provides compatibility with earlier Visual Basic versions. The syntax of the CVDate function is exactly the same as that of the CDate function. However, CVDate returns a Variant with a subtype of Date instead of the actual Date type. CVDate is no longer needed because the current Date type already exists. Convert an expression to Date and assign a value to Variant, which can achieve the same effect. You can also use this technique to convert other real data types into equal Variant subtypes.
Note that the CDec function cannot return an independent data type, but always returns a Variant. Its value has been converted to a Decimal subtype.
Cint () is a function in ASP.
Function converts an expression to a numeric type
Expression CInt (expression)
Allowed data type: Any valid characters are allowed.
Instance:
<%
F = "234"
Response. write cINT (f) 2
%>
Returned result: 236
The conversion character "234" is a number "234". If the string is null, 0 is returned.
We often see overflow errors of cint and clng. If a function is detected, this problem will not occur. The following two functions are written at the request of a friend. Let's take a look.
Checks whether the string is an integer.
Function Is_Int (a_str)
If not isnumeric (a_str) or len (str)> 5 then
Is_Int = false
Exit function
Elseif len (str) <5 then
Is_Int = true
Exit function
End if
If cint (left (a_str, 4)> 3276 then
Is_Int = false
Exit function
Elseif cint (left (a_str, 4) = 3276 and cint (right (a_str, 1)> 7 then
Is_Int = false
Exit function
Else
Is_Int = true
Exit function
End if
End function
Check whether it is a long integer
Function Is_Lng (a_str)
If not isnumeric (a_str) or len (str)> 10 then
Is_Lng = false
Exit function
Elseif len (str) <10 then
Is_Lng = true
Exit function
End if
If clng (left (a_str, 9)> 214748367 then
Is_Lng = false
Exit function
Elseif clng (left (a_str, 9) = 214748367 and clng (right (a_str, 1)> 7 then
Is_Lng = false
Exit function
Else
Is_Lng = true
Exit function
End if
End function