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
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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).
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top