I'm not too surprised that Math.Ceiling(414/var) gives 91.
Floating point representation is such that there is no floating point number
that matches 4.6f, only numbers that approximate it. Then,
Math.Ceiling(414/var) may very well return 91. This is not a bug, just a
consequence of floating point representation and computation rules.
So, before classifying these odd behaviors as "bugs", I suggest that you
read the specs (IEEE FP specs, C# specs) and see if the results that you get
contradict the specs. I doubt that that the odd results that you experienced
are actually bugs.
If you want to get predictable rounding, you should use the decimal type.
Double will be a bit better than float, but still, you will get odd
behaviors, this is inherent to the FP representation.
Bruno.
"Kubik" <ku***@iname.com> a écrit dans le message de
news:O3**************@TK2MSFTNGP11.phx.gbl...
Hi!
Let's see, we got:
float var=4.6f; //as we know 414/4.6 shoud be equal to 90
but Math.Ceiling(414/var) gives us 91
but (414/var).ToString() prints '90'.
And when we convert:
((double)(414/var)).ToString() we got '90,0000018658846'
I know how the floats are represented in memory and I know
limitations connected with, but why compiler and program
makes bugs in such simple cases??
Adam