Reputation: 5
I have a number, say 0.4 which is of class numeric. I wish to make it 2 decimal places without changing the class numeric. Is it possible to do this?
Upvotes: 0
Views: 113
Reputation: 24790
I'm not totally sure what you mean, but you can control the number of digits that print with sprintf
.
sprintf("%.2f",0.4)
# [1] "0.40"
Programmatically, 0.4
and 0.40
are identical.
all.equal(0.4,0.40)
# [1] TRUE
Upvotes: 1