Question

This fiddle return the correct value of "5,5" in both IE and FF but in Chrome it returns "5.5"

Fiddle: http://jsfiddle.net/4tvSH/

Globalize.culture("sv-SE");
alert(Globalize.format(5.5));

Is there a bug in the Globalize plugin?

edit:

This is strange, in Web.Config (MVC3) I have this

<globalization enableClientBasedCulture="true" />

Which means that the client sets the culture, both chrome and FF reports sv-SE, so the Globalize culture loaded is sv-SE like in the fiddle above.

But if i debug the code above on line 767 in Chrome

return culture.name.length ? value.toLocaleString() : value.toString();

value.toLocaleString() will return en-US format

This works, but its a hack..

//Fixes a bug in Globalize/Chrome where Globalize.format returns en-US format even with sv-SE
if($.browser.webkit == true) {
    Globalize.orgFormat = Globalize.format;
    Globalize.format = function(value, format) {
        if(format == null) {
            format = "N";
        }

        return this.orgFormat(value, format);
    };
}
Was it helpful?

Solution

Chrome does indeed seem to handle value.toLocaleString() in a different way from firefox, however I believe this should be considered as a Globalize bug.

I have corrected this behaviour in my Globalize fork, which was as simple as removing that toLocaleString iirc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top