1

I have a number like this: 1.79769313486232E+308 and I want to round it to the nearest whole number. so I tried the below one:

Math.Round(1.79769313486232E+308, 0)

But it still give the same result.

Can any one help me.?

Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105

4 Answers4

3

Since you have fewer than 309 digits after the dot your number is a whole number. The scientific notation must be confusing you, for example 1.234e+003 is also an integer because it's equal to 1234.

Joni
  • 108,737
  • 14
  • 143
  • 193
  • Ok..But then I want to make it as `1234`, how can it be done.? – Vishal Suthar Aug 16 '13 at 05:28
  • It's just a representation of your floating point number. Try `string.Format("{0:0}",yourNumber)`. @Joni: '1.234e+003' is not an integer, but it can be both converted to and printed as an integer. ;-) – alzaimar Aug 16 '13 at 05:40
  • 1
    @Joni Is it just me or everyone is getting `Floating-point constant is outside the range of type decimal` error – Rohit Aug 16 '13 at 05:42
  • @Joni Is `1.79769313486232E+308` equals to `$0` as someone told me that this number should be `$0` – Vishal Suthar Aug 16 '13 at 05:58
  • What do you mean by *$0*? Are you working with regular expressions or money or what? – Joni Aug 16 '13 at 06:21
  • Well then no, a huge number like this is not equal to zero. If the result of a calculation should be 0 and gives you this number instead you have a huge mistake somewhere. – Joni Aug 16 '13 at 06:24
  • Ok..Thanks..For all your help..:) – Vishal Suthar Aug 16 '13 at 06:28
1

The nearest whole number is the same number you've tryed to round up; it has 309 digits:

  1.79769313486232E+308 == 1797693134862320000....00

"E+308" in scientific notation means "multply this by 10 in 308th power". A simple example:

1.234E+3 == 1.234 * Math.Pow(10, 3) == 1.234 * 1000 == 1234

You can easily convince yourself by printing out the number:

  BigInteger b = BigInteger.Parse("1.79769313486232E+308", NumberStyles.Any, CultureInfo.InvariantCulture);
  Console.Write(b.ToString()); // <- 1797693134862320000....00
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0
double.Parse("1.00E+4", CultureInfo.InvariantCulture)

try this

backtrack
  • 7,996
  • 5
  • 52
  • 99
0

Worked for me

Add reference to System.Numerics if you are Using .NET framework 4.0 and then

 BigInteger b = BigInteger.Parse("1.79769313486232E+308", NumberStyles.Any, CultureInfo.InvariantCulture);
Rohit
  • 10,056
  • 7
  • 50
  • 82