We have a value coming from an Oracle database, thru web svcs that has the data type of float (over zealous dba). We need to display that value on a web page. We originally had a generic conversion routine:
public static decimal get_Decimal(object objIn)
{
decimal d = 0;
if (objIn == null)
{ return d; }
decimal.TryParse(objIn.ToString(), out d);
return d;
}
This worked fine until we had a value of -15856966. The TryParse failed and returned a 0. (The internal value was -1.58569E7, or something close to that.) Of course, 0 would not satisfy the users!!!
We then tried:
float f = (float)objIn;
d = (
decimal)f;
This returns -15856970, so it is rounding up and is 4 off.
I then tried to format the value for display purposes directly from the float:
string
d = String.Format( "{0:#,###,###,###.##;(#,###,###,###.##)}", this._nonLaborDollarsQy );
where _nonLaborDollarsQy is the float value. This returns -15,856,970.00, which, as you can see is still rounded up.
I am not sure where to go from here. I am sure the users are not going to be too happy with the rounded number.
Anyone have any ideas?
Thanks in advance for your help.