javascriptjqueryjquery-globalize

jQuery Globalize parse negative number


I'm having problems parsing negative numbers with jQuery Globalize 1.1.1:

Globalize.parseNumber('-1'); // = 1
Globalize.parseNumber('-100,00'); // = 100

So it seems Globalize is converting the negative number to a positive number. The following CLDR-data is loaded:

Failed to find anything on this via Google-searching. Am I missing something?


Solution

  • Globalize (1.1.x) deduces the minus sign symbol from CLDR when parsing. In Swedish (sv), the minus sign is āˆ’ (0x2212) not - (0x2D) as you have used in your example above. That's why it doesn't work for you. A quick test to assert parsing for negative numbers is:

    var sv = Globalize("sv");
    sv.parseNumber(sv.formatNumber(-100)) === -100; // > true
    

    Having said that, it seems like "Loose Matching" is a feature that might be of your interest. It would normalize the different types of dashes, no-break space to space, comma used as abbreviation, etc before parsing. It's not supported by Globalize. We track such feature here:

    https://github.com/jquery/globalize/issues/292