Phantomjs: Number.toLocaleString() doesn't apply appropriate formatting

Created on 19 Sep 2014  路  16Comments  路  Source: ariya/phantomjs

In all modern web browsers, the below snippet will output a formatted representation (with comma separation) of the number as shown below.

Modern Web Browser
var myFloat = 1234567890000.0;
console.log(myFloat.toLocaleString("en-GB"));

1,234,567,890,000

PhantomJS however doesn't seem to apply the en-GB locale formatting correctly:

PhantomJS
var myFloat = 1234567890000.0;
console.log(myFloat.toLocaleString("en-GB"));

1234567890000

Most helpful comment

+1

All 16 comments

+1

+1

+1

Someone asked for it already, and then closed the issue (see https://github.com/ariya/phantomjs/issues/12327). Personally, I don't think the solution proposed there makes sense.

My use case for this is simple: I have a unit test which exercises some code that uses toLocaleString(), and at the moment I have to execute that test _only when not running it through PhantomJS_. Not a very nice hack, IMO.

For the record, this is what I have in my test code:

if (!/PhantomJS/.test(window.navigator.userAgent)) {
    it('should do something which assumes a working toLocaleString', function() {
        // test code here
    }
}

+1

+1

+1

+1

Likewise for Date objects...

var objDate = new Date();
var locale = 'en-gb';
var month = objDate.toLocaleString(locale, {month: 'long'});

+1

+1

+1

+1

+1

+1

Any reason why this wont be resolved?

Qt/Webkit implements Number.prototype.toLocaleString as identical to Number.prototype.toString. It appears that the _very latest_ development sources of Webkit are changing this (see e.g. https://bugs.webkit.org/show_bug.cgi?id=147610) but those changes will take some time to appear in Qt/Webkit.

Internationalized number formatting is a sufficiently large Twinkie that we do not want to carry around patches for it.

Sorry.

Was this page helpful?
0 / 5 - 0 ratings