Rounding up decimals

M

Michael Malinsky

Assuming your value is stored in variable num:

Format(num, "#,##0.00")

Will put it in comma format.

HTH
Mike
--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh
 
M

MAS

Hi,

I have a msgbox that displays the result of some work , for example as
28.58333

How do i get the result to display just 2 decimal places, ie 28.58

M
 
J

Jerry W. Lewis

You can also call the worksheet round function as in
Application.Round(num, 2)
or if you have Excel 2000 or later, VBA has its own Round function.

Jerry
 
M

Myrna Larson

Just a caveat: the two functions (as I'm sure Jerry knows) give different
results when the digit to be rounded equals 5. Here's an example:

? round(2.5,0), application.round(2.5,0)

The above prints 2 and 3 as the results.
 
J

Jerry W. Lewis

Specifically, the VBA round function follows the rounding rules
specified by ASTM and many other standards bodies: by rounding to the
nearest rounded number, with ties (exactly 5) rounding up or down as
necessary to leave the last rounded digit even. The worksheet round
function uses the simplified rule that many people are more familiar
with: where ties always round up.

Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top