round() function in R Language is used to round off values to a specific number of decimal value.
Syntax: round(x, digits)
Parameters:
x: Value to be round off
digits: Number of digits to which value has to be round off
Example 1: Rounding off the values
Python3
x1 <- 1.2
x2 <- 1.8
x3 <- - 1.3
x4 <- 1.7
round(x1)
round(x2)
round(x3)
round(x4)
print(x1, x2, x3, x4)
|
Output :
1
2
-1
2
Here in the above code, we have round off the values with 4 data x1, x2, x3, and x4 using the function round(), and printed the new values.
Example 2: Rounding off to certain digits
Python3
x2 <- 3.14734343243
round(x2, digits = 3)
print(x2)
|
Output:
3.147
Here in the above code, the value of a numeric vector is round off till 3 digits.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!