0

Because Fortran, I need to write a program that, among other wonderful features, will force R to output a number in scientific notation with 3 significant figures after the decimal point.

Specifically, I need 170.5 to be written to output as 1.705e+02.

Using options(scipen = -999), I can force r to write 170.5 as 1.71e+02. However, this is insufficient for my use - ireally need that third digit after the period.

I think this question ought to be easy, but I am unable to figure out how to solve it. Thanks.

Jared Brewer
  • 132
  • 2
  • 12

2 Answers2

0

Perhaps try

options(scipen = -999, digits = 4)
user3170906
  • 98
  • 1
  • 5
0

Look at either sprintf or formatC.

sprintf("%s", 170.5)
[1] "1.705e+02"

 print( sprintf("%s", 170.5), quote=FALSE)
[1] 1.705e+02
IRTFM
  • 258,963
  • 21
  • 364
  • 487