0

I'm trying print to console or even inspect the numbers inside my dataframe object that contains big decimal numbers with 8 decimal places such as: "1054792997932.50564756" (the class of the number is numeric)

I tried using print() and cat() and View() to inspect a single number but the only result I get back is and integer "1054792997932" and the decimal places cannot be seen unless I use sprintf("%.8f", number) but the output I get back is the wrong number:

> sprintf("%.8f", 1054792997932.50564756)
[1] "1054792997932.50561523"

So from the looks of it sprintf is not a good method to use to check or format big decimal numbers.

I'm having problems validating and working with rounding such numbers any advice/help you can provide on how to deal with numbers in R would be appreciated as I am stuck

The system setup is:

R version: 3.4.0

I use pretty standard packages:

R stats and R Utils
Axeman
  • 32,068
  • 8
  • 81
  • 94
Alex
  • 1,630
  • 1
  • 20
  • 31
  • I suggest you study this answer: https://stackoverflow.com/a/9508558/1412059 – Roland Nov 28 '17 at 12:18
  • 1
    @LAP your example worked for displaying, thanks thats really useful, is there a way to use round with big numbers as well as we tried the following and it didn't work "> round(105479299792.675994873, 4)" => "[1] 105479299792.675994873" – Alex Nov 28 '17 at 12:22
  • Interesting. Your example works for me when rounding to either 1 or 0 decimals, but for more decimals it always displays `105479299792.67599`. I'm not sure why this does not work. It may be an artifact due to floating point arithmetic (see link @Roland provided). – LAP Nov 28 '17 at 12:27
  • Thanks for the help guys, @LAP f you could raise your response as an answer I will accept it, thanks again – Alex Nov 28 '17 at 13:22

1 Answers1

1

You can change the number of digits displayed in the console with the option "digits".

To view your current setting, type

getOption("digits")

The default setting is 7. With

options("digits" = 22)

you can change the setting. 22 is the maximum amount of digits R can display.

LAP
  • 6,605
  • 2
  • 15
  • 28