English 中文(简体)
VBA 反弹()操作员
原标题:Excel 2010 VBA Backslash () Operator
  • 时间:2012-05-28 03:39:35
  •  标签:
  • excel
  • vba

在学习 VBA时,我读到的每个来源都告诉我, 操作员执行整数分割。所以我想我可以用它来提取浮动点数的整数部分。

我有这样的电子表格:

A = 5
B = 50%

我需要计算: C = A x B ,四舍五入到最接近的整数(即,任何2.01、2.1、2.9、2.99等)。

我在想我可以做到这一点:

C = (A * B)  1

但是,这没有用----在我看来,浮控部分在进行整数分数之前是四舍五入的(即2.25改为3)。

我现在就做了这个:

 C = (A * B - 0.5)  1

在某些情况下不起作用(如果 A * B 完全等于一个整数,很可能代表问题)。

我还能做什么?

问题回答

看来我本可以做到的

Int(A * B)

得到我想要的

小心点:

any 2.01, 2.1, 2.9, 2.99 etc. all should be rounded down to 3

然后您不是在寻找 最接近整数 , 而是天花板函数。 最接近的整数听起来像圆形或固定函数( 您现在有作业: 查找两者之间的差异!)

关于上限功能,请看这里:

Excel 所使用的天花板函数 :

http://www.excelforum.com/excel-programing/62151-how-to-use-standard-excel-conform-in-vba.html

《VBA准则》上限功能:

http://www.tek-tips.com/faqs.cfm?fid=5031





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...