my Question for example.
if number is 1.1 or 1.2 or 1.3 or 1.4 then i want to answer (extract )only 1
else if number is 1.5 or 1.6 till 1.9 it should be 2
plz plz help me.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Karthik Muthu KaruppanPosted Jan 26, 2015, 5:01 PM
Gowtham RajamanickamPosted Apr 2, 2015, 7:14 AM
VulpesPosted Jan 26, 2015, 6:41 PM
https://msdn.microsoft.com/en-us/library/system.math.round%28v=vs.110%29.aspx
Note that a method such as Math.Round(double) always uses the so-called banker's rounding i.e. it rounds 0.5 to the nearer even digit.
So 1.5 would be rounded to 2 and 2.5 would also be rounded to 2.
If you want to always round 0.5 away from zero - so 1.5 would round to 2 and 2.5 to 3 - then use Math.Round(double, MidpointRounding.AwayFromZero).
This example illustrates these points:
The output is :
2
2
2
3
Karthik Muthu KaruppanPosted Jan 26, 2015, 5:50 PM
Karan GuptaPosted Jan 26, 2015, 5:21 PM
Karan GuptaPosted Jan 26, 2015, 5:15 PM