I want to convert the following VB code to C#:
Dim r as datarow
Dim i as integer
i = fix(r("NumberField"))
Fix as you may know truncates a floating point number to the right of the
decimal
point and returns an integer.
I have tried in C#:
i = convert.int32(r["NumberField"]) ' which produced rounding errors
i = round(r["NumberField"],0) ' which also produced rounding errors
i = (int) (r["NumberField"]) 'gives the correct results but
'raises an exception somtimes -
I think when the
value is NULL (this is data from
SQL)
I tried to write a function like:
private int fix(object o) {
return (int) o)
}
But this seems to produce numeric errors also.
So folks how do I write a "Fix" function in C#.
Thanks in advance ...Ed