+2 votes
in Programming Languages by (3.9k points)
Suppose I want to keep only 4 digits after the decimal point in a number. How can I limit the number of digits?

1 Answer

+2 votes
by (348k points)
selected by
 
Best answer

You can use either round() or format() function to limit the number of digits after the decimal place.

Here is an example:

> round(1.453245, digits = 4)
[1] 1.4532
> format(0.123235, digits=4)
[1] "0.1232"


...