ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Double variable value in excel (https://www.excelbanter.com/excel-discussion-misc-queries/173998-double-variable-value-excel.html)

Jeff

Double variable value in excel
 
Hi,

I had a question about how the double variable is used in excel.

When I program in C++ and I assign x = 2; where x is a double the actual
value is
1.999999999 or 2.000000011 but in excel it is exactly the number you assign
it.

I only ask because I was copying code from excel to C++ and part of the code
involved the expression

if (x = 3) then ...

But in C++ you could not use it because x was not always exactly equal to 3
and I ended up using "if (x2.99 and x<3.001)"

WHy is there a difference?

Thanks

David Biddulph[_2_]

Double variable value in excel
 
See your later question.
--
David Biddulph

"Jeff" wrote in message
...
Hi,

I had a question about how the double variable is used in excel.

When I program in C++ and I assign x = 2; where x is a double the actual
value is
1.999999999 or 2.000000011 but in excel it is exactly the number you
assign
it.

I only ask because I was copying code from excel to C++ and part of the
code
involved the expression

if (x = 3) then ...

But in C++ you could not use it because x was not always exactly equal to
3
and I ended up using "if (x2.99 and x<3.001)"

WHy is there a difference?

Thanks





All times are GMT +1. The time now is 02:19 PM.

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