Format scientific notation in R [duplicate]
Asked Answered
D

2

-1

I have a number which show as

a <- 1.34467773e-5. 

I want to format it to

a <- 1.34e-5. 

How can I do it?

Thanks.

Dialect answered 25/3, 2019 at 18:25 Comment(2)
options(digits=3)Pusillanimity
options() change the global options which might not be good for every situation, for example, I only want the p-values to be displayed in the scientific notation and other numbers in the default way.Meetly
E
2
formatC(a, format = "e", digits = 2)
Esra answered 25/3, 2019 at 18:28 Comment(1)
It's unclear in the question if the desired output is numeric or character, this is the latter. G5W's comment is the former.Cleavland
C
0

You could also use the function sprintf. For example:

sprintf("%.1e", 0.00008765)
Coloring answered 25/3, 2019 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.