3

5.35754303593134E+300 to 53575430359313400000000000000000000 ... 000000000

Can anyone do this because this number is very large?

I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            double s = double.Parse((System.Math.Pow(2, 999)).ToString(), System.Globalization.NumberStyles.Float);
            Console.WriteLine("value={0}", s);
            Console.ReadKey();
        }
    }
}
Chris Mantle
  • 6,595
  • 3
  • 34
  • 48

2 Answers2

1

Do one of the following,

Console.WriteLine(s.ToString("N0")); //comma separated
Console.WriteLine(s.ToString("F0")); 

Both works.

Abhishek
  • 6,912
  • 14
  • 59
  • 85
0

Your title and your code says different things but..

Basicly, you can't. decimal can't hold this value because it is way outside of it's range. It's range from 7.9 x 1028 to 7.9 x 1028.

You can save it on double (which Math.Pow return type and you don't even need to get it string representation and parse it to double again in such a case) or BigInteger.

double s = Math.Pow(2, 999);

or

BigInteger s = (BigInteger)Math.Pow(2, 999);

If you wanna get this value it's string representation, you can use "E" standard numeric format like;

s.ToString("E14") // 5,35754303593134E+300

Or you can use Jon Skeet's DoubleConverter class which exact representation of it's value;

DoubleConverter.ToExactString(s) // 5357543035931336604742125245300009052807024058527668037218751941851755255624680612465991894078479290637973364587765734125935726428461570217992288787349287401967283887412115492710537302531185570938977091076523237491790970633699383779582771973038531457285598238843271083830214915826312193418602834034688
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364