Convert decimal value to exponential value
-
Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this code in vb.net it returns 1.0E5 I need the same expression for the c#. I am using the following code String.Format("{0:E}", 100000) and its returns 1.000000E+005, but I need 1.0E5. The same for the another value String.Format("{0:E}", 0.000597), I need 5.97E-4 but it is returning 5.970000E-004. Does anyone let me know the right expression :confused:
Pankaj
-
Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this code in vb.net it returns 1.0E5 I need the same expression for the c#. I am using the following code String.Format("{0:E}", 100000) and its returns 1.000000E+005, but I need 1.0E5. The same for the another value String.Format("{0:E}", 0.000597), I need 5.97E-4 but it is returning 5.970000E-004. Does anyone let me know the right expression :confused:
Pankaj
-
Use
string.Format("{0:0.0E+00}", 1000000);
.50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
Thanks for your replay. When I run**
string.Format("{0:0.0E+00}", 0.000597);
**its return 6E-04 but I need 5.97E-4. I do not want to round the number.
Pankaj
-
Thanks for your replay. When I run**
string.Format("{0:0.0E+00}", 0.000597);
**its return 6E-04 but I need 5.97E-4. I do not want to round the number.
Pankaj
I have done some small changed in the expression and got the near of correct result
string.Format("{0:0.0E2}", 0.000597);
then its returns 5.97E-004. Can we remove 00 after the E ?
Pankaj
-
I have done some small changed in the expression and got the near of correct result
string.Format("{0:0.0E2}", 0.000597);
then its returns 5.97E-004. Can we remove 00 after the E ?
Pankaj
Got one solution
string.Format("{0:#.0#E-00}", 1000000);
Pankaj