[PATCH 2/8] jscript: Implement Number.prototype.toLocaleString.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Tue Apr 19 10:09:23 CDT 2022
On 19/04/2022 17:45, Jacek Caban wrote:
> On 4/15/22 15:00, Gabriel Ivăncescu wrote:
>> + if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5) {
>> + while(len--) {
>> + if(buf[len] != '0') {
>> + if(buf[len] == '.')
>> + remove_fraction = TRUE;
>> + break;
>> + }
>> + }
>> + }
>> +
>> + if(remove_fraction && GetLocaleInfoW(ctx->lcid, LOCALE_SDECIMAL,
>> buf, ARRAY_SIZE(buf))) {
>> + p = numstr;
>> + while(*p) {
>> + if(!(p = wcsstr(p, buf)))
>> + break;
>> + frac = p++;
>> + }
>> + if(frac) {
>> + tmp = jsstr_alloc_len(numstr, frac - numstr);
>> + jsstr_release(str);
>> + if(!tmp)
>> + return E_OUTOFMEMORY;
>> + str = tmp;
>> + }
>> + }
>
>
> This seems hackish, could we have share a helper with toString() and
> pass its result through GetNumberFormatW instead?
>
>
> Thanks,
>
> Jacek
>
I don't think sharing with toString will work, since toString seems to
add some logic around displaying exponents (scientific notation), which
GetNumberFormatW can't handle. And the result in toLocaleString never
displays an exponent even for very large numbers (but displays a ton of
digits with thousands separators).
If that's referring to the _swprintf_l part, that is.
I agree the removing fractions part is not exactly pretty, but I'm not
sure how to do it, since GetNumberFormatW adds fraction digits even if
they are zeros (if the locale settings are that way) while on native
mshtml they get stripped even with same locale settings! jscript
doesn't, though. Do you have better idea?
More information about the wine-devel
mailing list