Closed xhdong-umd closed 7 years ago
sprintf
looked to be better than format
here
> sprintf("%.3f", 19.8397782568591)
[1] "19.840"
> format(0.123234231, nsmall = 3)
[1] "0.1232342"
> sprintf("%.3f", 0.123234231)
[1] "0.123"
@xhdong-umd After playing around with sprintf
and format
, I like the digits
option of format
better because it allows me to set the number of significant digits, whereas %g
in sprintf
doesn't seem to allow that.
Yes, I just found format
support digits
and nsmall
at the same time, and it can convert to scientific notification if needed, so it probably is the best option here.
> format(123123123.123124, digits = 7)
[1] "123123123"
> format(123123123.123124, digits = 7, nsmall = 3)
[1] "123123123.123"
> format(0.0000123124, digits = 7, nsmall = 3)
[1] "1.23124e-05"
> format(13242342342342.12, digits = 7, nsmall = 3)
[1] "1.324234e+13"
> format(0.123234231, digits = 7, nsmall = 3)
[1] "0.1232342"
This is a minor cosmetic issue. Currently the importing data process give messages with lots of digits after decimal point.
Should we limit the digits after decimal points to maybe 2 or 4? Of course the significant digits will have higher priority for values like
0.00001
(or use scientific notation in that case).