0

4.18121555349556E-05

I want to convert this to decimal or double so that the output will be like 0.0000418121555349556 but that value is inside a variable so I can't use this format - decimal myDecimalValue = Decimal. Parse("value", System. Globalization. NumberStyles. any);

  • Does this answer your question? [How to convert double to string without the power to 10 representation (E-05)](https://stackoverflow.com/questions/1319191/how-to-convert-double-to-string-without-the-power-to-10-representation-e-05) – Magnetron Mar 27 '20 at 12:22
  • not really because what is shown there is that the value is being specified and being converted while my problem is that my value is inside a variable and my value changes because it has formula – Shanaia Secret Mar 27 '20 at 12:22
  • 1
    in this case, the problem you think you have does not exist. the string representation of the variable does not in any way affect the internal representation of the decimal in a variable, its precision, or computations with it. it is just two different ways of displaying the exactly same number. – Cee McSharpface Mar 27 '20 at 12:24
  • so it's like i need to have a code to convert that variable before it produce the result/value – Shanaia Secret Mar 27 '20 at 12:24
  • @ShanaiaSecret You have to separate things. One thing is the variable value, the data that is stored. You don't need to know that or worry about it. The other thing is the string representation of that value (a human readable form). That you specify in the occasion you want to display for the user (or when you parse a string provided by the user), with the questions provided above. – Magnetron Mar 27 '20 at 12:26
  • 1
    There is no conversion necessary. You are reading the value properly. You just want to display the data in a different format. See msdn : https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings – jdweng Mar 27 '20 at 12:35
  • @jdweng thanks for the link, I will look into it. – Shanaia Secret Mar 27 '20 at 12:41

1 Answers1

0

Try this

public static void Main()
{
    //use System.Globalization.NumberStyles.Any
    decimal h2 = Decimal.Parse("4.18121555349556E-05", System.Globalization.NumberStyles.Any);
    Console.WriteLine(h2.ToString());
}
nonoandy
  • 120
  • 15