Link to home
Start Free TrialLog in
Avatar of kishan66
kishan66Flag for United States of America

asked on

Check datatype in C#.net

Hi,
i need to call a user-defined conversion function "ScientificToDecimal" when ever value retrieved is not float

  some times values is like   >> 2.125900000000000e+004        OR        >> 2.12
so i want to convert  from Scientific to Decimal if the value is not float datatype.
Note:- 'ScientificToDecimal'  function works fine though

Is there a way ?

Environment:-  C#net,  ASP.Net 2.0


/// sample code ////
 if ((float.TryParse(drowpnl["start_qty"].ToString(), out flt)))
{
 decimal dc_start_qty =  scientificTOdecimal(drowpnl["start_qty"].ToString());
 drowpnl["start_qty"] = string.Format("{0:N2}", dc_start_qty);
}

//// ScientificTodecimal /////
 protected decimal scientificTOdecimal(string varstr)
 {
   return (decimal.Parse(varstr,    System.Globalization.NumberStyles.Float));
 }

Open in new window

Avatar of malikirfan28
malikirfan28

try the following code
string x = "2.125900000000000e+004";
            double d = Double.Parse(x, System.Globalization.NumberStyles.Float)

Open in new window

Avatar of kishan66

ASKER

Hi mali kirfan28,

as i mentioned, String x is not always  in this format ( Ex:-"2.125900000000000e+004";)

Avatar of Todd Gerbert
I'm not sure what you're asking...do you mean if the string is "Hello World" you don't want to try and convert it to a decimal?
Hello tgerbert,

i am trying read values from xml file ... which are in Scientific format... and some in decimal

so i want to convert those which are in scientific format Ex:-"2.125900000000000e+004";

do i make any sense........
i 'm sorry if my basic approach is wrong... would appreciate if corrected



So if it's NOT in scientific notation you don't want to convert it, even if it's a valid  decimal value?

Give me an example of what should be converted, and what shouldn't, and why.
ASKER CERTIFIED SOLUTION
Avatar of malikirfan28
malikirfan28

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial