ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unwanted Rounding Errors (https://www.excelbanter.com/excel-programming/301040-unwanted-rounding-errors.html)

Anson[_2_]

Unwanted Rounding Errors
 
I set a variable as "single" and gather the value from in cell in Excel, say a percentage. When I spit out the same variable back to the worksheet, I got a slightly different number. For example 12% will become 0.1200000000542. Obviously this causes problem when I do data vailadion since these two numbers are now not equal. I don't want to round a number everytime when I deal with a number, any suggestion?

Frank Kabel

Unwanted Rounding Errors
 
Hi
you have to use Round or something similar. See
http://www.cpearson.com/excel/rounding.htm
for an explanantion why this happens

In addition I won't use 'Single' but 'Double' as variable type. No real
need for a 'Single' variable type


--
Regards
Frank Kabel
Frankfurt, Germany


Anson wrote:
I set a variable as "single" and gather the value from in cell in
Excel, say a percentage. When I spit out the same variable back to
the worksheet, I got a slightly different number. For example 12%
will become 0.1200000000542. Obviously this causes problem when I do
data vailadion since these two numbers are now not equal. I don't
want to round a number everytime when I deal with a number, any
suggestion?




All times are GMT +1. The time now is 01:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com