Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Using the Round function in VBA code in Excel

Hi all
I'm trying to round a number so that it has 2 decimal places. However I've come across this bizarre incident where by the following gives me 2 ??

x = Round(2.005, 2)

I expected it to return me 2.01

Any help would be hugely appreciated
Paul
0
skintpaul
Asked:
skintpaul
1 Solution
 
chandukbCommented:
This code works:

Dim x As Single
x = Application.WorksheetFunction.Round(2.005, 2)
MsgBox x

I just tried.

hope this helps.

Chandu

0
 
jrspanoCommented:
this is a 3rd same question delete it
0
 
rmarimanCommented:
Is the type of x able to contain decimals?
I just tried this out in Excel 97 VBA and I cannot find a builtin Round function!
Entering this in an excel cell it works correctly.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now