I'm stumped with what's happening here. I have a value in a CSV that I
want to round. I wanted to use CSng to force the single data type so
that an error would not occur from trying to round a text string. My
code is simple:

Cells(i, 8).Value = Round(CSng(Cells(i, 10).Value, 4))

where i is an integer used in a loop to run down the cells in columns 8
and 10.

For some reason when I set the value in Cell(i,8), Excel is adding some
apparently random erroneous digits to the end of the value. So for
example, a value appearing as 12.1294 in Cell(i,10) comes out as
12.12946789 in Cell(i,8). It appears to be something that happens when
I insert the value into a cell too. If I just display
Round(CSng(Cells(i, 10).Value, 4))
in a Msgbox everything looks fine. Anybody know what might be causing
this? I'm running MS VB 6.0 with MS Excel 2000.

Re: CSng adds erroneous digits to the value by Bob

Bob
Wed Jun 07 17:43:05 CDT 2006

ben.biddle@gmail.com wrote:

> in a Msgbox everything looks fine. Anybody know what might be
> causing this? I'm running MS VB 6.0 with MS Excel 2000.

So why are you posting to a vbscript newsgroup? ISTM a VB group, or
better yet, an Excel newsgroup would have been a logical choice ...

You're probably running into one of the consequences of using floats:
Many numbers cannot be stored accurately in binary.
http://www.google.com/search?sourceid=gd&rls=GGLD,GGLD:2005-37,GGLD:en&hl=en&oe=UTF-8&q=floating-point%20errors%20site%3Asupport.microsoft.com&sa=N&tab=xw
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.