View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Mike Mike is offline
external usenet poster
 
Posts: 3,101
Default Rounding Problem

Jerry,

Thanks for the code. I have used the record macro before. I should have
thought of that before posting that question.

I'm still not clear on what is happening in the first place. My program
rounds the number to a single decimal before it ever puts it into the
spreadsheet. So, the spreadsheet shouldn't even see any extra decimal
positions. Also, if you look at the decimal values added, they are
consistant and repeat. It's like excel added them. I've even used MsgBox to
view the value before it is entered into the spreadsheet and it only has one
decimal place.

Any insight into what is happening is appreciated.

Mike


"Jerry W. Lewis" wrote:

Formatting a cell impacts the way that the value is displayed, but does not
change the value itself (unrounded). If you want to calculate with rounded
values, you either have to explicitly round them, or set the Precision as
Displayed option.

When you are unsure how to program an operation, record a macro while you do
it manually and examine the code. From that you would find
ActiveWorkbook.PrecisionAsDisplayed = True

Jerry

"Mike" wrote:

Also, what I don't understand is why the extra decimal positions were there
in the first place. The number I enter using the program had already been
rounded to a single decimal point. Why did excel generate the extra
positions?

Mike


"Bob Umlas, Excel MVP" wrote:

Format the cells with one decimal place, then use Tools/Options/Calculation
tab, and check "Precision as displayed". Click OK to the message about losing
accuracy.
Bob Umlas
Esxcel MVP

"Mike" wrote:

I'm having a problem with rounding that I hope someone can help with. I've
written code in VB to take readings from a piece of test equipment and round
the value to a single decimal point before putting it into a spreadsheet.
The problem is that the actual values in the cells have 13 decimal places.
The cells are formatted as a number with one decimal place and that is how
they are displayed in the cell of the spreadsheet. But, when I click on the
cell and the actual value in shown in the Formula Bar, it shows the value
with 13 decimals places.

Code:
Dim TempStr As Single
TempStr = Round(Mid(ValueStr, 2, 14), 1)
Sheets("Temps").Cells(Rrow, (X * 2)) = TempStr

Results:
Cell Shows in Formula Bar
23.7 23.7000007629394
23.8 23.7999992370605
23.9 23.8999996185302
24.0 24
24.1 24.1000003814697
24.2 24.2000007629394
24.3 24.2999992370605
24.4 24.3999996185302
24.5 24.5
24.6 24.6000003814697
24.7 24.7000007629394
24.8 24.7999992370605
24.9 24.8999996185302
25.0 25