Decimal numbers?

zzcom

Active Member
Joined
Aug 4, 2004
Messages
272
When VBA macro has some integers to work with how many decimal places those integers have by default, and is it possible to change it to three decimal places( 0.001 for example) or four (0.0001), etc
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

just_jon

Legend
Joined
Sep 3, 2002
Messages
10,473
Integers have no decimal portions, other than zero.
Book1.xls
ABCD
11.00000
21.333333333333330
31.33330
41.33330
5
6
Sheet3
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> foo()<SPAN style="color:#00007F">Dim</SPAN> i<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Integer</SPAN>
i = 1 + (1 / 3)
[a1] = i<SPAN style="color:#00007F">Dim</SPAN> j<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Double</SPAN>
j = 1 + (1 / 3)
[a2] = j
[a3] = Round(j, 4)
[a4] = Application.WorksheetFunction.Round(j, 4)<SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN></FONT>

A caveat, when using VBA's Round function:

{from MS}
Although the Round function is useful for returning a number with a specified number of decimal places, you can't always predict how it will round when the rounding digit is a 5. How VBA rounds a number depends on the internal binary representation of that number. If you want to write a rounding function that will round decimal values according to predictable rules, you should write your own. For more information, see the Visual Basic Language Developer's Handbook by Ken Getz and Mike Gilbert (Sybex, 1999).
 

Watch MrExcel Video

Forum statistics

Threads
1,118,084
Messages
5,570,129
Members
412,305
Latest member
Mozz
Top