Skip to content

CLNG


将数值或字符串表达式转换为 Long 类型

语法

vb
declare function Clng ( byval expression as datatype ) as long

Type typename

declare operator cast ( ) as long

End Type

用法

vb
result = Clng( numeric expression )
result = Clng( string expression )
result = Clng( user defined type )

参数

expression

要转换为 Long 值的数值、字符串或指针表达式

datatype

任何数值、字符串或指针数据类型

typename

用户自定义类型

返回值

Long 值。

说明

Clng 函数舍去小数部分并返回 32 位 Long 值。该函数不检查溢出,对于小于 -2147483648 或大于 2147483647 的值,结果是未定义的。

函数名可以理解为"转换为长整型"(Convert to LoNG)。

如果参数是字符串表达式,则使用 Valint 将其转换为数值。

示例

start GeSHi

vb
' Using the CLNG function to convert a numeric value

'Create an LONG variable
Dim numeric_value As Long

'Convert a numeric value
numeric_value = CLng(-300.23)

'Print the result, should return -300
Print numeric_value
Sleep

end GeSHi

与 QB 的差异

  • QB 不允许字符串参数

另请参阅

  • Cbyte
  • Cubyte
  • Cshort
  • Cushort
  • Cint
  • Cuint
  • Culng
  • Clngint
  • Culngint
  • Csng
  • Cdbl

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系