Re: Why there are two diffrent result in two almost same formula
- From: "David" <david.colliver.NEWS@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 10 Jun 2009 13:05:03 +0100
What happens if you change
Single result2 = System.Convert.ToSingle(XNT * num) / SX;
to
Single result2 = System.Convert.ToSingle((XNT * num) / SX);
?
First one, you are modifying the left side before dividing. Second one, you
are modifying the result. I would suggest the second one would be correct.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"XjAcKs" <xjacks@xxxxxxxxx> wrote in message
news:eb4IoIb6JHA.5756@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for you reply. My english is poor, so I will have to read your
reply for a while. If I find out something later, I will send a reply.
BTW: I just try the program in .NET 3.5/VS 2008, and the result the
same as .NET 2.0/VS 2005, so I think it seems not a complier bug or it
haven't been fixed.
I just try my code in Java language, and the expression's result is the
same value: 0.6985381. So I think the expression with ToSingle() method
is right...
I think I have figured out out.
I changed the variables definition "result" and "result2" to Double and I
delete the "SX" in expression. And it is :
int num = 3600;
Single XNT = 0.3F;
Double result = XNT * num ;
Double result2 = System.Convert.ToSingle(XNT * num);
And, the value of two result is:
result -> 1080.00004291534
result2 -> 1080
It seems that Single is more better than Double here...
Single result = (XNT * num) / SX;
Single result2 = System.Convert.ToSingle(XNT * num) / SX;
So I think in the first expression, the result of "XNT * num" is a type of
Double.
But why one Single variable multiply another Single variable, the result
is a type of Double? How weird it is...
.
- Follow-Ups:
- References:
- Why there are two diffrent result in two almost same formula
- From: XjAcKs
- Re: Why there are two diffrent result in two almost same formula
- From: XjAcKs
- Re: Why there are two diffrent result in two almost same formula
- From: Peter Duniho
- Re: Why there are two diffrent result in two almost same formula
- From: XjAcKs
- Re: Why there are two diffrent result in two almost same formula
- From: XjAcKs
- Re: Why there are two diffrent result in two almost same formula
- From: XjAcKs
- Re: Why there are two diffrent result in two almost same formula
- From: XjAcKs
- Why there are two diffrent result in two almost same formula
- Prev by Date: RE: Merge XML Files from DataSets
- Next by Date: Re: code access security
- Previous by thread: Re: Why there are two diffrent result in two almost same formula
- Next by thread: Re: Why there are two diffrent result in two almost same formula
- Index(es):
Relevant Pages
|