Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprintf doesn't care about OutDec option #477

Open
yurasmol opened this issue May 7, 2022 · 5 comments
Open

Sprintf doesn't care about OutDec option #477

yurasmol opened this issue May 7, 2022 · 5 comments

Comments

@yurasmol
Copy link

yurasmol commented May 7, 2022

options(OutDec=",")
val = 0.86771
sprintf("%.3f", val)
#[1] "0.868"

@gagolews
Copy link
Owner

gagolews commented May 7, 2022

Yes, this is mentioned in the documentation of help("options")...

OutDec: character string containing a single character. The preferred character to be used as the decimal point in output conversions, that is in printing, plotting, format and as.character but not when deparsing nor by sprintf nor formatC (which are sometimes used prior to printing.)

@gagolews
Copy link
Owner

gagolews commented May 7, 2022

Interestingly, https://linux.die.net/man/3/sprintf mentions that

For some numeric conversions a radix character ("decimal point") or thousands' grouping character is used. The actual character used depends on the LC_NUMERIC part of the locale. The POSIX locale uses '.' as radix character, and does not have a grouping character. Thus, printf("%'.2f", 1234567.89); results in "1234567.89" in the POSIX locale, in "1234567,89" in the nl_NL locale, and in "1.234.567,89" in the da_DK locale.

But this is not supported by base R

@gagolews
Copy link
Owner

gagolews commented May 7, 2022

Stringi does not have it either - it is related to the (still missing) feature of formatting numerals (#81)

@yurasmol
Copy link
Author

yurasmol commented May 7, 2022 via email

@gagolews
Copy link
Owner

gagolews commented May 7, 2022

It is definitely a feature worth having - added to the to-do list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants