Decimals and Rounding

Decimals and Rounding

Welcome to our Knowledge Base

Documentation | Blog | Demos | Support

< All Topics
Print

Decimals and Rounding

The result of an arithmetic expression contains as many decimal places as are found in the operands of the expression.

If the expression contains several operands with varying numbers of decimal places, the result takes on the number of decimal places found in the operand with the most decimal places.

If the result of the expression is assigned to an object with a numeric data type, the value takes on the number of decimal places defined for that object. If the object has fewer rounded decimal places than the expression’s result, the final value is rounded as shown in the following example:

5/2

Evaluates to 3

5/2.0

Evaluates to 2.5

1+1.01

Evaluates to 2.01

1.01+(5/2)

Evaluates to 3.51

Rounding occurs only after the entire expression has been evaluated. Therefore, in 1.01+(5/2), the fractional part of 5/2 is kept during the addition of 1.01. Because 1.01 has two decimal places, the result also has two decimal places.

Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.

Leave a Reply

Your email address will not be published. Required fields are marked *

en_CAEnglish