Core: Documentation for ',' option in double formatting, thousands separator '@' flag for double formatting.

git-svn-id: svn://ultimatepp.org/upp/trunk@4161 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-11-11 14:01:55 +00:00
parent 809cfe6d29
commit 68425c7f56
5 changed files with 111 additions and 105 deletions

View file

@ -618,6 +618,7 @@ String RealFormatter(const Formatting& f)
while(IsDigit(*++s))
;
}
if(*s == '@') { s++; flags |= FD_NOTHSEPS; }
if(*s == ',') { s++; flags |= FD_COMMA; }
if(*s == '!') { s++; flags |= FD_ZERO; }
if(*s == '^') {

View file

@ -36,15 +36,17 @@ template<> inline String AsString(const uint64& a) { return Format64(a)
enum
{
FD_SIGN = 0x01, // always prepend sign (+10)
FD_REL = 0x02, // relative decimal places (valid digits)
FD_SIGN_EXP = 0x04, // always prepend sign to exponent (1e+2)
FD_CAP_E = 0x08, // capital E for exponent (1E10)
FD_ZERO = 0x10, // keep trailing zeros (1.25000)
FD_FIX = 0x20, // always use fixed notation (FormatDouble)
FD_EXP = 0x40, // always use exponential notation (FormatDouble)
FD_COMMA = 0x80, // use ',' instead of '.'
FD_SIGN = 0x01, // always prepend sign (+10)
FD_REL = 0x02, // relative decimal places (valid digits)
FD_SIGN_EXP = 0x04, // always prepend sign to exponent (1e+2)
FD_CAP_E = 0x08, // capital E for exponent (1E10)
FD_ZERO = 0x10, // keep trailing zeros (1.25000)
FD_FIX = 0x20, // always use fixed notation (FormatDouble)
FD_EXP = 0x40, // always use exponential notation (FormatDouble)
FD_COMMA = 0x80, // use ',' instead of '.'
FD_NOTHSEPS = 0x100, // In i18n, do not use thousands separators
};
String FormatDoubleDigits(double d, int digits, int flags, int& exponent);
String FormatDouble(double d, int digits, int flags = 0, int fill_exp = 0);
String FormatDoubleFix(double d, int digits, int flags = 0);

View file

@ -480,7 +480,9 @@ String LanguageInfo::FormatDouble(double value, int digits, int FD_flags, int fi
{
if(IsNull(value))
return Null;
return NlsFormatRaw(UPP::FormatDouble(value, digits, FD_flags, fill_exp), thousand_separator, decimal_point);
return NlsFormatRaw(UPP::FormatDouble(value, digits, FD_flags, fill_exp),
FD_flags & FD_NOTHSEPS ? String() : thousand_separator,
FD_flags & FD_COMMA ? "," : decimal_point);
}
String LanguageInfo::FormatDate(Date date) const

View file

@ -173,7 +173,10 @@ limit.&]
]_[* Pattern]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 p])&]
[s2; Formatting tag used for conversion to textual representation
(includes standard printf formatting tags, see Format function
for description). Default tag is [@4 %.10g].&]
for description). Default tag is [@4 %.10g]. After setting a new
pattern, ConvertDouble formats simple example number (Format(1.1))
and if it detects character `',`' in resulting string, Filter
method forces `',`' to be used instead of `'.`' for decimal point.&]
[s7; [%-*C@3 p]-|Pattern.&]
[s7; [*/ Return value]-|`*this.&]
[s3; &]

View file

@ -193,13 +193,16 @@ section is almost always escaped using [* `[] [* `]].&]
[s0; &]
[s0; The format of [*@(0.0.255) options] is&]
[s0; &]
[s0; [*@4 `[][* `+][*@4 `]`[`[][* `-][*@4 `]][*@(0.0.255) digits][*@4 `]`[][* !][*@4 `]`[][* `^][*@4 `[][* `+
][*@4 `]][*@(0.0.255) expdig][*@4 `]]&]
[s0; [*@4 `[][* `+][*@4 `]`[`[][* `-][*@4 `]][*@(0.0.255) digits][*@4 `]`[][* `@][*@4 `]`[][* ,][*@4 `]`[][* !
][*@4 `]`[][* `^][*@4 `[][* `+][*@4 `]][*@(0.0.255) expdig][*@4 `]]&]
[s0; &]
[s0;O9;~~~.576; `+-|always prepend sign&]
[s0;O9;~~~.576; [*@4 `[][* `-][*@4 `]][*@(0.0.255) digits][@(0.0.255) -|]number
of decimals to print (negative `= left of decimal point, default
`= 6)&]
[s0;O9;~~~.576; `@-|do not use thousands separators (in internationalized
formatting)&]
[s0;O9;~~~.576; ,-|use `',`' instead of `'.`' for decimal point&]
[s0;O9;~~~.576; [* !]-|keep insignificant zeros&]
[s0;O9;~~~.576; [* `^]-|exponent options:&]
[s0;l160;O9;~~~.640; [* `+]-|always prepend sign to exponent&]
@ -210,132 +213,127 @@ width&]
[s0; &]
[s0;%- [*/ Examples of standard formatters]&]
[s0; &]
[ {{5311:4689 [s0;%- Format(`"[* %d], [* %s]`", 123, `"TEXT`")]
:: [s0;%- [C 123, TEXT]]
:: [s0;%- Format(`"[* %2:s], [* %1:d]`", 123, `"TEXT`")]
:: [s0;%- [C TEXT, 123]]
[s0;3%- &]
[ {{5073:4927 [s0;%- Format(`"[* %d, %s]`", 123, `"TEXT`")]
:: [s0;%- 123, TEXT]
:: [s0;%- Format(`"[* %2:s, %1:d]`", 123, `"TEXT`")]
:: [s0;%- TEXT, 123]
:: [s0;%- Format(`"[* %010d]`", 123)]
:: [s0;%- [C 0000000123]]
:: [s0;%- 0000000123]
:: [s0;%- Format(`"[* %0`*d]`", 11, 123)]
:: [s0;%- [C 00000000123]]
:: [s0;%- Format(`"`|[* %20<d]`|`", 123)]
:: [s0;%- [C `|123 `|]]
:: [s0;%- Format(`"`|[* %20>d]`|`", 123)]
:: [s0;%- [C `| 123`|]]
:: [s0;%- Format(`"`|[* %20`=d]`|`", 123)]
:: [s0;%- [C `| 123 `|]]
:: [s0;%- Format(`"[* %d``]pt`", 123)]
:: [s0;%- [C 123pt]]
:: [s0;%- Format(`"[* %`[empty`]`~d], [* %`[empty`]`~d]`", 123, Null)]
:: [s0;%- [C 123, empty]]
:: [s0;%- Format(`"[* %``]`", 123)]
:: [s0;%- [C 123]]
:: [s0;%- 00000000123]
:: [s0;%- Format(`"[* `|%20<d`|]`", 123)]
:: [s0;%- `|123 `|]
:: [s0;%- Format(`"[* `|%20>d`|]`", 123)]
:: [s0;%- `| 123`|]
:: [s0;%- Format(`"[* `|%20`=d`|]`", 123)]
:: [s0;%- `| 123 `|]
:: [s0;%- Format(`"[* %dpt]`", 123)]
:: [s0;%- 123pt]
:: [s0;%- Format(`"[* %`[empty`]`~d, %`[empty`]`~d]`", 123, Null)]
:: [s0;%- 123, empty]
:: [s0;%- Format(`"[* %]`", 123)]
:: [s0;%- 123]
:: [s0;%- Format(`"[* %c]`", 65)]
:: [s0;%- [C A]]
:: [s0;%- A]
:: [s0;%- Format(`"[* %d]`", 123)]
:: [s0;%- [C 123]]
:: [s0;%- 123]
:: [s0;%- Format(`"[* %i]`", 123)]
:: [s0;%- [C 123]]
:: [s0;%- 123]
:: [s0;%- Format(`"[* %o]`", 123)]
:: [s0;%- [C 173]]
:: [s0;%- 173]
:: [s0;%- Format(`"[* %x]`", 123)]
:: [s0;%- [C 7b]]
:: [s0;%- 7b]
:: [s0;%- Format(`"[* %X]`", 123)]
:: [s0;%- [C 7B]]
:: [s0;%- Format(`"[* %e]`", 1.23)]
:: [s0;%- [C 1.230000e`+000]]
:: [s0;%- Format(`"[* %E]`", 1.23)]
:: [s0;%- [C 1.230000E`+000]]
:: [s0;%- Format(`"[* %f]`", 1.23)]
:: [s0;%- [C 1.230000]]
:: [s0;%- Format(`"[* %g]`", 1.23)]
:: [s0;%- [C 1.23]]
:: [s0;%- Format(`"[* %G]`", 1.23)]
:: [s0;%- [C 1.23]]
:: [s0;%- Format(`"[* %n]`", 1.23)]
:: [s0;%- [C 1.23]]
:: [s0;%- Format(`"[* %1n]`", 1.23)]
:: [s0;%- [C 1.2 ][/ (explicit number of decimals)]]
:: [s0;%- Format(`"[* %3!n]`", 1.23)]
:: [s0;%- [C 1.230 ][/ (force insignificant zeros)]]
:: [s0;%- Format(`"[* %ne]`", 1.23)]
:: [s0;%- [C 1.23e0]]
:: [s0;%- Format(`"[* %2`^`+3ne]`", 1.23)]
:: [s0;%- [C 1.2e`+000 ][/ (exponent formatting)]]
:: [s0;%- Format(`"[* %nf]`", 1.23e30)]
:: [s0;%- [C 1230000000000000000000000000000]]
:: [s0;%- Format(`"[* %nl]`", 1.23)]
:: [s0;%- [C 1,23]]
:: [s0;%- Format(`"[* %v]`", 1.23)]
:: [s0;%- [C 1.23]]
:: [s0;%- Format(`"[* %2v]`", 1.23)]
:: [s0;%- [C 1.2 ][/ (2 valid digits)]]
:: [s0;%- Format(`"[* %2v]`", 123)]
:: [s0;%- [C 120 ][/ (2 valid digits)]]
:: [s0;%- Format(`"[* %ve]`", 1.23)]
:: [s0;%- [C 1.23e0]]
:: [s0;%- Format(`"[* %vf]`", 1.23e30)]
:: [s0;%- [C 1230000000000000000000000000000]]
:: [s0;%- Format(`"[* %vl]`", 1.23)]
:: [s0;%- [C 1,23]]
:: [s0;%- 7B]
:: [s0;%- Format(`"[* %e]`", 1234567.89)]
:: [s0;%- 1.234568e`+006]
:: [s0;%- Format(`"[* %E]`", 1234567.89)]
:: [s0;%- 1.234568E`+006]
:: [s0;%- Format(`"[* %f]`", 1234567.89)]
:: [s0;%- 1234567.890000]
:: [s0;%- Format(`"[* %g]`", 1234567.89)]
:: [s0;%- 1.23457e`+006]
:: [s0;%- Format(`"[* %G]`", 1234567.89)]
:: [s0;%- 1.23457E`+006]
:: [s0;%- Format(`"[* %n]`", 1234567.89)]
:: [s0;%- 1234567.89]
:: [s0;%- Format(`"[* %,n]`", 1234567.89)]
:: [s0;%- 1234567,89]
:: [s0;%- Format(`"[* %ne]`", 1234567.89)]
:: [s0;%- 1234567.89]
:: [s0;%- Format(`"[* %nf]`", 1234567.89e30)]
:: [s0;%- 1234567890000000000000000000000000000]
:: [s0;%- Format(`"[* %nl]`", 1234567.89)]
:: [s0;%- 1,234,567.89]
:: [s0;%- Format(`"[* %`@nl]`", 1234567.89)]
:: [s0;%- 1234567.89]
:: [s0;%- Format(`"[* %`@,nl]`", 1234567.89)]
:: [s0;%- 1234567,89]
:: [s0;%- Format(`"[* %v]`", 1234567.89)]
:: [s0;%- 1234570]
:: [s0;%- Format(`"[* %ve]`", 1234567.89)]
:: [s0;%- 1234570]
:: [s0;%- Format(`"[* %vf]`", 1234567.89e30)]
:: [s0;%- 1234570000000000000000000000000000000]
:: [s0;%- Format(`"[* %vl]`", 1234567.89)]
:: [s0;%- 1,234,570]
:: [s0;%- Format(`"[* %`[1:one;2:two;3:three;another`]s]`", 2)]
:: [s0;%- [C two]]
:: [s0;%- two]
:: [s0;%- Format(`"[* %`[1:one;2:two;3:three;another`]s]`", 20)]
:: [s0;%- [C another]]
:: [s0;%- another]
:: [s0;%- Format(`"[* %`[3%1:one;2:two;3:three;another`]s]`", 20)]
:: [s0;%- [C two]]
:: [s0;%- two]
:: [s0;%- Format(`"[* %month]`", 6)]
:: [s0;%- [C june]]
:: [s0;%- june]
:: [s0;%- Format(`"[* %Month]`", 6)]
:: [s0;%- [C June]]
:: [s0;%- June]
:: [s0;%- Format(`"[* %MONTH]`", 6)]
:: [s0;%- [C JUNE]]
:: [s0;%- JUNE]
:: [s0;%- Format(`"[* %mon]`", 6)]
:: [s0;%- [C jun]]
:: [s0;%- jun]
:: [s0;%- Format(`"[* %Mon]`", 6)]
:: [s0;%- [C Jun]]
:: [s0;%- Jun]
:: [s0;%- Format(`"[* %MON]`", 6)]
:: [s0;%- [C JUN]]
:: [s0;%- JUN]
:: [s0;%- Format(`"[* %day]`", 6)]
:: [s0;%- [C saturday]]
:: [s0;%- saturday]
:: [s0;%- Format(`"[* %Day]`", 6)]
:: [s0;%- [C Saturday]]
:: [s0;%- Saturday]
:: [s0;%- Format(`"[* %DAY]`", 6)]
:: [s0;%- [C SATURDAY]]
:: [s0;%- SATURDAY]
:: [s0;%- Format(`"[* %dy]`", 6)]
:: [s0;%- [C sa]]
:: [s0;%- sa]
:: [s0;%- Format(`"[* %Dy]`", 6)]
:: [s0;%- [C Sa]]
:: [s0;%- Sa]
:: [s0;%- Format(`"[* %DY]`", 6)]
:: [s0;%- [C SA]]
:: [s0;%- SA]
:: [s0;%- Format(`"[* %tw]`", 0)]
:: [s0;%- [C 12]]
:: [s0;%- 12]
:: [s0;%- Format(`"[* %tw]`", 5)]
:: [s0;%- [C 5]]
:: [s0;%- 5]
:: [s0;%- Format(`"[* %tw]`", 15)]
:: [s0;%- [C 3]]
:: [s0;%- 3]
:: [s0;%- Format(`"[* %0tw]`", 15)]
:: [s0;%- [C 03]]
:: [s0;%- 03]
:: [s0;%- Format(`"[* %a]`", 1)]
:: [s0;%- [C a]]
:: [s0;%- a]
:: [s0;%- Format(`"[* %a]`", 123)]
:: [s0;%- [C es]]
:: [s0;%- es]
:: [s0;%- Format(`"[* %A]`", 1)]
:: [s0;%- [C A]]
:: [s0;%- A]
:: [s0;%- Format(`"[* %A]`", 123)]
:: [s0;%- [C ES]]
:: [s0;%- ES]
:: [s0;%- Format(`"[* %r]`", 8)]
:: [s0;%- [C viii]]
:: [s0;%- viii]
:: [s0;%- Format(`"[* %R]`", 1231)]
:: [s0;%- [C MCCXXXI]]
:: [s0;%- Format(`"[* %``]`", GetSysDate())]
:: [s0;%- [C 08/25/2006]]
:: [s0;%- Format(`"[* %``]`", GetSysTime())]
:: [s0;%- [C 08/25/2006 20:37:09]]
:: [s0;%- Format(`"[* %``]`", `"text`")]
:: [s0;%- [C text]]
:: [s0;%- Format(`"[* %``]`", GetSysDate())]
:: [s0;%- [C 25.08.2006]]}}&]
:: [s0;%- MCCXXXI]
:: [s0;%- Format(`"[* %]`", GetSysDate())]
:: [s0;%- 11/11/2011]
:: [s0;%- Format(`"[* %]`", GetSysTime())]
:: [s0;%- 11/11/2011 14:44:11]
:: [s0;%- Format(`"[* %]`", `"text`")]
:: [s0;%- text]}}&]
[s0; &]
[s0; &]
[s0; &]