1

I want to do a Double to String conversion, but there's a problem. If I convert a Double to a String with the following code:

static void Main(string[] args)
{
    double dou = 1000000000000000000;
    // Result dou = 1E+18
    string str = dou.ToString();
    // Again Result str = 1E+18
}

I need the result to be str = 1000000000000000000.

How do I do this?

dbc
  • 104,963
  • 20
  • 228
  • 340
Michael Stone
  • 105
  • 3
  • 12
  • Might this be C#? Please explicitly mention what programming language this is supposed to be! – Xan-Kun Clark-Davis Sep 12 '18 at 19:53
  • Looks like a duplicate of [Double to string conversion without scientific notation](https://stackoverflow.com/q/1546113/3744182), agree? – dbc Apr 23 '21 at 16:37

2 Answers2

0

Is it C#?

https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings#the-numeric-n-format-specifier Try play with:

dou.ToString("N")
PKCS12
  • 407
  • 15
  • 41
0

This should work

decimal dec = (decimal)dou;
string str = dec.ToString();
nick
  • 1,611
  • 4
  • 20
  • 35