gagolews / stringi

Fast and portable character string processing in R (with the Unicode ICU)
https://stringi.gagolewski.com/
Other
300 stars 45 forks source link

Sprintf doesn't care about OutDec option #477

Open yurasmol opened 2 years ago

yurasmol commented 2 years ago

options(OutDec=",") val = 0.86771 sprintf("%.3f", val)

[1] "0.868"

gagolews commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

yurasmol commented 2 years ago

But this is reflected in a large number of other libraries.

От: Marek Gagolewski Отправлено: 7 мая 2022 г. в 10:37 Кому: gagolews/stringi Копия: yurasmol; Author Тема: Re: [gagolews/stringi] Sprintf doesn't care about OutDec option(Issue #477)

Stringi does not have it either - it is related to the (still missing) feature of formatting numerals (#81) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

gagolews commented 2 years ago

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