The trade-offs of decimals

Source: Internet
Author: User

1. Math.floor &math.ceiling (floor--; ceiling--) Math.floor: Returns the maximum integer value that is less than or equal to the specified decimal. Math.floor (3.21);//3Math.floor (5.952);//5Math.floor (0.64);//0Math.floor (-0.64);//-1Math.floor (-5.2);//-6Math.floor (-5.8);//-6math.ceiling: Returns the smallest integer value greater than or equal to the specified decimal. Math.ceiling (3.21);//4Math.ceiling (5.952);//6Math.ceiling (0.64);//1Math.ceiling (-0.64);//0Math.ceiling (-5.2);//-5Math.ceiling (-5.8);//-5Note: The return type is double or decimal. 2. Math.truncate Rounding/truncation Effect: Calculates the integer portion of the specified decimal. Example: Math.truncate (3.21);//3Math.truncate (5.952);//5Math.truncate (0.64);//0Math.truncate (-0.64);//0Math.truncate (-5.2);//-5Math.truncate (-5.8);//-5Note: The return type is double or decimal. 3. Math.Round Rounding Effect: Math.Round takes the same rounding method as Convert.ToInt32 (Double), and is used bankers'rounding rules (four homes six into 50% pairs)Example: Math.Round (3.21);//3Math.Round (5.5);//6Math.Round (4.5);//4Math.Round (-0.64);//-1Math.Round (-5.5);//-6Math.Round (-4.5);//-4decimal Trade-offs: Math.Round (Double, Int32), where Int32 specifies the number of decimal places for the return value. Example: Math.Round (3.44,1);//Returns 3.4.Math.Round (3.45,1);//Returns 3.4.Math.Round (3.46,1);//Returns 3.5.Math.Round (4.34,1);//Returns 4.3Math.Round (4.35,1);//Returns 4.4Math.Round (4.36,1);//Returns 4.4pasted from//msdn.microsoft.com/zh-cn/library/zy06z30k.aspx>extension: The function by default is according to bankers'The rounding rule (quad six into 50% pairs) is rounded. To allow for more flexible rounding, the function adds the system.midpointrounding parameter. Midpointrounding.awayfromzero: In positive cases, this is the most common rounding. In the case of negative numbers,-4.5--5。 (Negative case,-4.5 Rounding is-4 or-5, everyone has different opinions). Midpointrounding.toeven: Is the default four six into 50% pairs. 

Transfer from http://blog.sina.com.cn/s/blog_6d5a77ce0100xpcb.html

The trade-offs of decimals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.