Conversions: Difference between revisions
Created page with "'''Function''' CBOOL(''expression'') CBYTE(''expression'') CCUR(''expression'') CDATE(''expression'') CDBL(''expression'') CINT(''expression'') CLNG(''expression'') CS..." |
|||
(22 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
'' | ''This function is for BASIC compatibility. It is not available in pure JavaScript projects.'' | ||
== Function == | |||
CBool(''expression'') | |||
CByte(''expression'') | |||
CCur(''expression'') | |||
CDate(''expression'') | |||
CDbl(''expression'') | |||
CInt(''expression'') | |||
CLng(''expression'') | |||
CSng(''expression'') | |||
'' | CStr(''expression'') | ||
The conversion functions return an expression that has been converted to the appropriate type. The required parameter, expression, is any valid expression. | == Description == | ||
The conversion functions return an expression that has been converted to the appropriate type. The required parameter, ''expression'', is any valid expression. | |||
If the return value lies outside the acceptable range of its return type, an error occurs. | If the return value lies outside the acceptable range of its return type, an error occurs. | ||
Line 27: | Line 29: | ||
'''Table 5: Conversion Functions''' | '''Table 5: Conversion Functions''' | ||
{| class="wikitable" | |||
|- | |||
! Function !! Returns !! Comments | |||
|- | |||
| CBool || Boolean || False if expression is zero True otherwise | |||
|- | |||
| CByte || Byte || A whole number that ranges from 0 to 255 | |||
|- | |||
| CCur || Currency || A Currency Datum | |||
|- | |||
| CDate || Date || Date range January 1, 100 to December 31, 9999, | |||
Valid expressions are date expressions, or date/time literals | |||
|- | |||
| CDbl || Double || Number ranges from | |||
-1.79769313486232E308 to | |||
-4.94065645841247E-324 for negative values, and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values | |||
|- | |||
| CInt || Integer || Number ranges from -32,768 to 32,767, values with fractional parts (fp) are rounded | |||
fp < 0.5 rounded down | |||
fp > 0.5 rounded up | |||
fp = 0.5 rounded to nearest even number | |||
|- | |||
| CLng || Long Integer || Number ranges from | |||
-2,147,483,648 to 2,147,483,647, values with fractional parts (fp) are rounded | |||
fp < 0.5 rounded down | |||
fp > 0.5 rounded up | |||
fp = 0.5 rounded to nearest even number | |||
|- | |||
| CSng || Single || Number ranges from | |||
-3.403823E38 to | |||
-1.401298E-45 for negative numbers, and from | |||
1.401298E-45 to 3.403823E38 for positive numbers | |||
|- | |||
| CStr || String || •Booleans are converted to "True" or "False" | |||
•Dates converted to short-date format of system | |||
•Errors converted to "Error <number>" | |||
•Numbers converted to string containing the number | |||
|} | |||
== Example (Basic) == | |||
<pre> | <pre> | ||
Rem Conversion Functions Example | |||
Print "CByte(99.44) = " & CByte(99.44) | |||
Print "CCur(9283.066) = " & CCur(9283.066) | |||
Print "CDate(8/18/98) = " & CDate("8/18/98") | |||
Print "CDbl(3.141593) = " & CDbl("3.141593") | |||
Print "CInt(3.141593) = " & CInt("3.141593") | |||
Print "CSng(10) = " & CSng(10) | |||
Print "CStr(TRUE) = " & CStr(TRUE) | |||
Print "CInt(""&h100"") = " & CInt("&h100") | |||
</pre> | </pre> | ||
== Output == | |||
<pre> | <pre> | ||
CByte(99.44) = 99 | |||
CCur(9283.066) = 9283.066 | |||
CDate(8/18/98) = 8/18/1998 | |||
CDbl(3.141593) = 3.141593 | |||
CInt(3.141593) = 3 | |||
CSng(10) = 10 | |||
CStr(TRUE) = True | |||
CInt("&h100") = 256 | |||
</pre> | </pre> | ||
== Related Items == | |||
[[is (function)|Is]], [[number|Number]] | |||
[[Category:Language Reference]] | |||
[[Category:Strings]] | |||
[[ | [[Category:BASIC Functions]] |
Latest revision as of 15:19, 25 March 2019
This function is for BASIC compatibility. It is not available in pure JavaScript projects.
Function
CBool(expression)
CByte(expression)
CCur(expression)
CDate(expression)
CDbl(expression)
CInt(expression)
CLng(expression)
CSng(expression)
CStr(expression)
Description
The conversion functions return an expression that has been converted to the appropriate type. The required parameter, expression, is any valid expression.
If the return value lies outside the acceptable range of its return type, an error occurs.
Table 5: Conversion Functions
Function | Returns | Comments |
---|---|---|
CBool | Boolean | False if expression is zero True otherwise |
CByte | Byte | A whole number that ranges from 0 to 255 |
CCur | Currency | A Currency Datum |
CDate | Date | Date range January 1, 100 to December 31, 9999,
Valid expressions are date expressions, or date/time literals |
CDbl | Double | Number ranges from
-1.79769313486232E308 to -4.94065645841247E-324 for negative values, and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values |
CInt | Integer | Number ranges from -32,768 to 32,767, values with fractional parts (fp) are rounded
fp < 0.5 rounded down fp > 0.5 rounded up fp = 0.5 rounded to nearest even number |
CLng | Long Integer | Number ranges from
-2,147,483,648 to 2,147,483,647, values with fractional parts (fp) are rounded fp < 0.5 rounded down fp > 0.5 rounded up fp = 0.5 rounded to nearest even number |
CSng | Single | Number ranges from
-3.403823E38 to -1.401298E-45 for negative numbers, and from 1.401298E-45 to 3.403823E38 for positive numbers |
CStr | String | •Booleans are converted to "True" or "False"
•Dates converted to short-date format of system •Errors converted to "Error <number>" •Numbers converted to string containing the number |
Example (Basic)
Rem Conversion Functions Example Print "CByte(99.44) = " & CByte(99.44) Print "CCur(9283.066) = " & CCur(9283.066) Print "CDate(8/18/98) = " & CDate("8/18/98") Print "CDbl(3.141593) = " & CDbl("3.141593") Print "CInt(3.141593) = " & CInt("3.141593") Print "CSng(10) = " & CSng(10) Print "CStr(TRUE) = " & CStr(TRUE) Print "CInt(""&h100"") = " & CInt("&h100")
Output
CByte(99.44) = 99 CCur(9283.066) = 9283.066 CDate(8/18/98) = 8/18/1998 CDbl(3.141593) = 3.141593 CInt(3.141593) = 3 CSng(10) = 10 CStr(TRUE) = True CInt("&h100") = 256