Thursday, January 12, 2006

.NET 247 : C# equivalent question on microsoft.public.dotnet.languages.csharp: "Posted in haste...

Actually the MSDN defines Fix(number) = Sign(number) * Int(Abs(number))

I think the following is equivalent

(x >= 0 ? Math.Floor(x) : Math.Ceiling(x))

there may be a better way to replace it though.

Watch out for 'rounding' errors.

The MSDN Math.Floor sample shows:

Floor(1.00) = 0

because after 11 subtractions of 0.1 from 2.1 'value' ends up with a number slightly less than 1.0

If you set 'value' to exactly 1.0 you get the following result
Floor(1.00) = 1

Decimal.Trunctate may also be worth a look

Returns the integral digits of the specified Decimal; any fractional digits are discarded.
Return Value: The Decimal result of d rounded toward zero, to the nearest whole number."

0 Comments:

Post a Comment

<< Home