4

Let's do some rounding

> round(-0.001, 2)
[1] 0

I receive zero.

Now in combination with sprintf

> sprintf("%f", round(-0.001,2))
[1] "-0.000000"

Why is there a minus sign? I expected 0.000000.

$R --version
R version 2.13.1 (2011-07-08)
woobert
  • 482
  • 5
  • 14

1 Answers1

8

It's the nature of floating point numbers (IEEE 754), there is a -0 defined. See -0.

Femaref
  • 60,705
  • 7
  • 138
  • 176