EXCEL Processing of numbers in , Often round by the specified number of digits as needed .
Rounding of numbers can be done with the following functions :
Rounding =ROUND(A1,0)
Truncate decimals and round =ROUNDDOWN(A1,0) =FLOOR(A1,1) =TRUNC(A1)
Truncate the decimal to the nearest even number =EVEN(A1)
Truncate decimals and take integers upward =CEILING(A1,1)
Truncate decimals and round down =INT(A1)
C Languages have the following rounding methods :
1, Direct assignment to integer variables . as :
int i = 2.5; or i = (int) 2.5;
This method uses rounding off the decimal part
2,C/C++ Integer division operator in “/” It has rounding function (int / int), However, the integer division of negative numbers and the use of rounding results C Compiler related .
3, use floor function .floor(x) Returns less than or equal to x Maximum integer of . as :
floor(2.5) = 2
floor(-2.5) = -3
4, use ceil function .ceil(x) Returned is greater than x Minimum integer of . as :
ceil(2.5) = 3
ceil(-2.5) = -2
floor() Is rounded to negative infinity ,floor(-2.5) = -3;ceil() Is rounded to positive infinity ,ceil(-2.5) = -2.
MATLAB There are many rounding functions in , List its usage for convenience in the future :
floor
B = floor(A) Return less than or equal to A Integer value of , For the plural , Respectively A Real part and imaginary part of .
a = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i]
a =
Columns 1 through 6
-1.9000 -0.2000 3.4000 5.6000 7.0000 2.4000 + 3.6000i
floor(a)
ans =
Columns 1 through 6
-2.0000 -1.0000 3.0000 5.0000 7.0000 2.0000 + 3.0000i
ceil
B = ceil(A) Return greater than or equal to A Integer value of , For the plural , Respectively A Real part and imaginary part of .
a = [-1.9, -0.2, 3.4, 5.6, 7, 2.4+3.6i]
a =
Columns 1 through 6
-1.9000 -0.2000 3.4000 5.6000 7.0000 2.4000 + 3.6000i
ceil(a)
ans =
Columns 1 through 6
-1.0000 0 4.0000 6.0000 7.0000 3.0000 + 4.0000i
round:
Y = round(X) Return distance X Nearest integer value .
a = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i]
a =
Columns 1 through 4
-1.9000 -0.2000 3.4000 5.6000 7.0000 2.4000 + 3.6000i
round(a)
ans =
Columns 1 through 4
-2.0000 0 3.0000 6.0000 7.0000 2.0000 + 4.0000i
fix:
B = fix(A) return A Integer part of , The decimal part is 0
a = [-1.9, -0.2, 3.4, 5.6, 7.0, 2.4+3.6i]
a =
Columns 1 through 4
-1.9000 -0.2000 3.4000 5.6000 7.0000 2.4000 + 3.6000i
fix(a)
ans =
Columns 1 through 4
-1.0000 0 3.0000 5.0000 7.0000 2.0000 + 3.0000i
Technology