C# equivalent question

  • Thread starter Thread starter Same
  • Start date Start date
S

Same

I am trying to convert a VB6 app into C# and I cannot find an equivalent to
VB6's Fix Function. Does anyone know if there is one or how to get around
it?

Thanks
 
Forgot to say I do not want to include VB.Net Runtime and use:
Microsoft.VisualBasic.Conversion.Fix

Thanks
 
Same said:
I am trying to convert a VB6 app into C# and I cannot find an equivalent to
VB6's Fix Function. Does anyone know if there is one or how to get around
it?

Thanks

I think you are looking Math.Ceiling
(However did they came up with "Fix" in VB I don't know...
somebody must have skipped math class)
 
Same,
Have you looked at the System.Math class?

Specifically Math.Floor & Math.Ceiling?

Math.Floor matches Fix, however you may want to use Math.Ceiling if you have
negative numbers...

Hope this helps
Jay
 
Same said:
I am trying to convert a VB6 app into C# and I cannot find an equivalent to
VB6's Fix Function. Does anyone know if there is one or how to get around
it?

Thanks

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.
 
Back
Top