0

i want more decimal places in round function.

if i give

data<-c(2.768687963684727856934786)

round(data,digits = 20)

2.76868796368473

in that result i got only 14 decimals only after decimal point, how can i get more decimals(means 20). Any help would be greatly appreciated. Thank you!

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • 2
    try `options(digits = 20)` – mtoto Mar 22 '16 at 14:28
  • 1
    actually you have all 20 decimals, but only 14 are displayed in the console because that's how the option `digits` is set in your session. You can try `sprintf("%.20f", round(data,digits = 20))` to display all 20 (though it will be converted into `character`) – Cath Mar 22 '16 at 14:32
  • thanks for your reply, but as.numeric(sprintf("%.20f", round(data,digits = 20))) is giving only 16 decimals only – Praveen Kesani Mar 22 '16 at 14:51
  • Note that by default R uses [double precision](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) numbers which are only accurate to about 16 digits. If you need more then some arbritrary precision package like [this](https://cran.r-project.org/web/packages/Rmpfr/index.html) is needed. – bdecaf Mar 22 '16 at 14:54

0 Answers0