Skip to content

Commit

Permalink
Merge remote branch 'kflorence/44'
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaefferer committed Jul 25, 2011
2 parents dab6f69 + 727b180 commit 858f490
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/globalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -1489,16 +1489,28 @@ Globalize.parseFloat = function( value, radix, cultureSelector ) {
ret = parseInt( value, 16 );
}
else {

// determine sign and number
var signInfo = parseNegativePattern( value, nf, nf.pattern[0] ),
sign = signInfo[ 0 ],
num = signInfo[ 1 ];
// determine sign and number

// #44 - try parsing as "(n)"
if ( sign === "" && nf.pattern[0] !== "(n)" ) {
signInfo = parseNegativePattern( value, nf, "(n)" );
sign = signInfo[ 0 ];
num = signInfo[ 1 ];
}

// try parsing as "-n"
if ( sign === "" && nf.pattern[0] !== "-n" ) {
signInfo = parseNegativePattern( value, nf, "-n" );
sign = signInfo[ 0 ];
num = signInfo[ 1 ];
}

sign = sign || "+";

// determine exponent and number
var exponent,
intAndFraction,
Expand Down
6 changes: 6 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ test("basics, currency", function() {
equal( Globalize.parseFloat("$5.51"), 5.51 );
equal( Globalize.parseInt("($5.51)"), -5 );
equal( Globalize.parseFloat("($5.51)"), -5.51 );

// #44 - The cultures "lo" and "lo-LA" are unique in that they
// use the format "(n)" in both currency and number formatting
equal( Globalize.parseInt("(5.51₭)", "lo"), -5 );
equal( Globalize.parseFloat("(5.51₭)", "lo"), -5.51 );

equal( Globalize.parseInt("5,51 €", 10, "de-DE"), 5 );
equal( Globalize.parseFloat("5,51 €", 10, "de-DE"), 5.51 );
equal( Globalize.parseFloat("5,51 €", "de-DE"), 5.51, "optional radix" );
Expand Down

0 comments on commit 858f490

Please sign in to comment.