एमएसडीएन के विवरण के लिए इन लिंक का पालन करें:
Math.Floor
, which rounds down towards negative infinity.
Math.Ceiling
, which rounds up towards positive infinity.
Math.Truncate
, which rounds up or down towards zero.
Math.Round
, which rounds to the nearest integer or specified number of decimal places. You can specify the behavior if it's exactly equidistant between two possibilities, such as rounding so that the final digit is even ("Round(2.5,MidpointRounding.ToEven)
" becoming 2) or so that it's further away from zero ("Round(2.5,MidpointRounding.AwayFromZero)
" becoming 3).
निम्नलिखित चित्र और तालिका मदद कर सकती है:
-3 -2 -1 0 1 2 3
+--|------+---------+----|----+--|------+----|----+-------|-+
a b c d e
a=-2.7 b=-0.5 c=0.3 d=1.5 e=2.8
====== ====== ===== ===== =====
Floor -3 -1 0 1 2
Ceiling -2 0 1 2 3
Truncate -2 0 0 1 2
Round (ToEven) -3 0 0 2 3
Round (AwayFromZero) -3 -1 0 2 3
ध्यान दें कि round
ऐसा लगता है कि यह बहुत अधिक शक्तिशाली है, क्योंकि यह दशमलव स्थानों की एक विशिष्ट संख्या के लिए गोल कर सकता है। सभी अन्य शून्य दशमलव के लिए हमेशा दौर। उदाहरण के लिए:
n = 3.145;
a = System.Math.Round (n, 2, MidpointRounding.ToEven); // 3.14
b = System.Math.Round (n, 2, MidpointRounding.AwayFromZero); // 3.15
अन्य कार्यों के साथ, आपको एक ही प्रभाव प्राप्त करने के लिए गुणा / विभाजित ट्रिकरी का उपयोग करना होगा:
c = System.Math.Truncate (n * 100) / 100; // 3.14
d = System.Math.Ceiling (n * 100) / 100; // 3.15