0

If I do

126.887429023806 + 0.0120214904747417

in R, it returns

[1] 126.8995

Instead of 126.8994505142807417

How do I preserve more decimals?

Rafael
  • 3,096
  • 1
  • 23
  • 61
  • 1
    You could specify `digits` in `print` i.e. `print(126.887429023806 + 0.0120214904747417, digits = 16)` – akrun May 10 '21 at 20:05
  • so are those extra digits carried but not printed? ie if I use the result of that addition in another calculation will all 16 decimals be used? – Rafael May 10 '21 at 20:07
  • 1
    If you want to change this behavior you can change the global `option(digitis=x)` , but it is not really recommended – Elia May 10 '21 at 20:08
  • According to `?print.default` `digits - a non-null value for digits specifies the minimum number of significant digits to be printed in values. The default, NULL, uses getOption("digits"). (For the interpretation for complex numbers see signif.) Non-integer values will be rounded down, and only values greater than or equal to 1 and no greater than 22 are accepted.` – akrun May 10 '21 at 20:08
  • 1
    You may want to read the FAQ [Why are these numbers not equal?](https://stackoverflow.com/q/9508518/903061) to understand a bit more about how floating point numbers work under the hood, and become aware of a common pitfall. – Gregor Thomas May 10 '21 at 20:10

0 Answers0