如何使用excel VBA圆()? [英] How to round up with excel VBA round()?

查看:204
本文介绍了如何使用excel VBA圆()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据:

cell(1,1) = 2878.75
cell(1,2) = $31.10
cell(2,1) = $89,529.13

然而,当我试图使用 round(cells(1,1).value * cells(1,2).value),2),结果不匹配单元格(2,1)。我认为它与四舍五入的问题有关,但我只是想知道是否可以使 round()正常运行。也就是说,对于 value> 0.5 ,综合起来。而对于值< 0.5 ,向下舍入?

However, when I tried to use round(cells(1,1).value*cells(1,2).value),2), the result does not match cell(2,1). I figured it has to do with the rounding issue, but I'm just wondering if it is possible to get round() to act normally. That is, for value > 0.5, round up. And for value < 0.5, round down?

推荐答案

VBA使用

VBA uses bankers rounding in an attempt to compensate for the bias in always rounding up or down on .5; you can instead;

WorksheetFunction.Round(cells(1,1).value * cells(1,2).value, 2)

这篇关于如何使用excel VBA圆()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆