c语言int function,CInt Function

CInt 函数将任何类型的表达式转换为 Integer 子类型的 Variant。它使用系统的区域设置进行转换,能正确识别不同文化和语言的数字分隔符。当数值超出 Integer 范围时,会出现错误。CInt 在遇到分数部分恰好为 0.5 的情况时会进行偶数舍入。与 Fix 和 Int 函数不同,CInt 会四舍五入而不是直接截断小数部分。
摘要由CSDN通过智能技术生成

CInt Function

10/24/2011

閱讀時間 2 分鐘

本文內容

Returns an expression that has been converted to a Variant of subtype Integer.

CInt(expression)

Remarks

The expression argument is any valid expression.

Use the CInt function to provide conversions from any other data type to an Integer subtype. For example, CInt forces integer arithmetic when currency, single-precision, or double-precision arithmetic would normally occur.

The CInt function uses the locale setting of your system to determine how to perform conversions. Different decimal separators are properly recognized depending on the locale setting, as are different thousand separators.

If expression lies outside the acceptable range for the Integer subtype, an error occurs.

The following example uses the CInt function to convert a value to an integer.

Dim MyDouble, MyInt

MyDouble = 2345.5678 ' MyDouble is a Double.

MyInt = CInt(MyDouble) ' MyInt contains 2346.

Note

When the fractional part of a value is exactly 0.5, the CInt function rounds to the closest even number. For example, 0.5 rounds to 0, 1.5 rounds to 2, and 3.5 rounds to 4. The purpose of rounding to the closest even number is to compensate for a bias that could accumulate when many numbers are added together.

CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number.

Requirements

See Also

Reference

Change History

Date

History

Reason

August 2009

Modified remarks.

Customer feedback.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值