Reputation: 17193
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.?
Upvotes: 1
Views: 1151
Reputation: 186668
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
Upvotes: 1
Reputation: 10236
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);
Upvotes: 0
Reputation: 111239
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.
Upvotes: 3