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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Karthik Muthu KaruppanRank #671 · 3.6K reputationPosted Jan 26, 2015, 12:01 PM EST
VulpesRank #55 · 29.2K reputationPosted Jan 26, 2015, 1:41 PM EST
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 KaruppanRank #671 · 3.6K reputationPosted Jan 26, 2015, 12:50 PM EST
Karan Gupta28 reputationPosted Jan 26, 2015, 12:15 PM EST
Karan Gupta28 reputationPosted Jan 26, 2015, 12:21 PM EST
Gowtham RajamanickamRank #57 · 29K reputationPosted Apr 2, 2015, 3:14 AM EDT