'Microsoft Excel converts all numbers to Scientific Notations

Whenever I enter any integer in Excel it converts it to Scientific notation, Below is the result when I add 1, 2, 3:

enter image description here

How do I stop this? If I type 1. it considers it as integer.



Solution 1:[1]

Resolved. Found the culprit.
The following setting was enabled somehow in File-> Options-> Advanced
and set to 20 decimal places.

enter image description here

Solution 2:[2]

Not quite sure why Prasad deleted their answer - it looked close to being a solution for you, just was using the wrong culture for parsing..

Anyways, parse your number using its culture and then print the result of turning the number to a string with different cultures

var germanCulture = System.Globalization.CultureInfo.GetCultureInfo("de-de");
     
decimal sourceValue = decimal.Parse("0,123", germanCulture);
string target_invariant = sourceValue.ToString(System.Globalization.CultureInfo.InvariantCulture);
string targetValue = sourceValue.ToString(germanCulture);
Console.WriteLine(target_invariant);
Console.WriteLine(targetValue);     

Credit for most of this code goes to sir rufo's fiddle, it just didn't have the parsing step in, which seemed rather vital to your overall mission

Solution 3:[3]

Let's take a look at the implementation of String.ToString():

// Returns this string.
public override string ToString()
{
    return this;
}

// Returns this string.
public string ToString(IFormatProvider? provider)
{
    return this;
}

As you can see just the same instance gets returned. This is also reflected in the documentation, which will show up in intellisense (but i'm unsure whether that is from visual studio of the resharper plugin):

enter image description here

What you should do is parse the string to an floating point data type and then convert that to the appropriate culture.

string sourceValue = "0,123";
var sourceInt = double.Parse(sourceValue, CultureInfo.InvariantCulture);

string target_invariant = sourceValue;
string targetValue = sourceInt.ToString(CultureInfo.CurrentUICulture);

This will use double.ToString(...) which actually uses the culture:

public string ToString(IFormatProvider? provider)
{
    return Number.FormatDouble(m_value, null, NumberFormatInfo.GetInstance(provider));
}

Solution 4:[4]

Instead of converting string into another string with InvariantCulture won't help you to convert decimal value with .,

You need to parse given sourceValue to decimal with german culture,

//You can parse as double too.
decimal result = decimal.Parse(sourceValue, CultureInfo.GetCultureInfo("de-de"));

Now you can print with . using CultureInfo.InvariantCulture,

Console.WriteLine(result.ToString(CultureInfo.InvariantCulture));

Try online : .Net Fiddle

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vishal R
Solution 2 Caius Jard
Solution 3 sommmen
Solution 4