Division calculation issues in C #

Source: Internet
Author: User

 

Response. Write ("<br>" + 4/3); // 1
The result of Division and Division is an integer.
Division rounds the result to zero, and the absolute value of the result is the maximum possible integer that is smaller than the absolute value of the quotient of the two operands. When the two operand symbols are the same, the result is zero or positive. When the two operand symbols are the opposite, the result is zero or negative.
If the left operand is the smallest value, it can be an int or long value, and the right operand is-1, overflow occurs. Whether the operation occurs in the checked or unchecked context, system. overflowexception is always triggered.
If the value of the right operand is zero, system. dividebyzeroexception is thrown.

Esponse. Write ("<br>" + 5% 2); // 1 obtain the remainder

Response. Write ("<br>" + 4/3.0); // 1.33333333333333
The result is of the double type, precise to 15-16 digits.
This parameter 3.0 is specified as the double type.

Response. Write ("<br>" + 4/3f); // 1.333333
The result is float type, precise to 7 digits.
This parameter 3f is specified as float type.

 

Appendix:

Both integer and floating point types can be used in an expression. In this case, the integer type is converted to the floating point type. Calculate the expression according to the following rules:

If one of the floating point types is double, the expression is calculated as double or bool (for relational expressions or boolean expressions ).

If the expression does not have the double type, the calculation result of the expression is of the float type, and the relational expression or Boolean expression is of the bool type.

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.