zuneH Lee
zuneH Lee

Reputation: 1

Numeric value printing format options in R (decimal and digits)

I have a question about the numeric value printing format with global options

My global option is as below.

options(digits = 5)

It works as ...

# type 1
> 123.1234
123.12
# type 2
>1234.1234
1234.1

I want it working like below by modifying global options.(without using round() function) please see below result

> 1234.1234
1234.12

Anybody can help me?

Upvotes: 0

Views: 123

Answers (1)

Minions
Minions

Reputation: 1313

Use formatC(x,digits=2,format="f")

Output :

formatC(123.1234,digits=2,format="f")
[1] "123.12"
formatC(1234.1234,digits=2,format="f")
[1] "1234.12"

Upvotes: 2

Related Questions