kishan66
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
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));
}
ASKER
Hi mali kirfan28,
as i mentioned, String x is not always in this format ( Ex:-"2.125900000000000e+00 4";)
as i mentioned, String x is not always in this format ( Ex:-"2.125900000000000e+00
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?
ASKER
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+00 4";
do i make any sense........
i 'm sorry if my basic approach is wrong... would appreciate if corrected
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+00
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.
Give me an example of what should be converted, and what shouldn't, and why.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window