Skip to content

Commit

Permalink
Fixed decimals: 0
Browse files Browse the repository at this point in the history
  • Loading branch information
leongersen committed Jun 14, 2014
1 parent b9c449a commit 3a5e1bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 11 additions & 2 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
equal ( Tester.from ( '-79?900_041' ), -79900.041 );
});

test( "Testing 0 decimals", function(){

var Tester = wNumb({
decimals: 0
});

equal ( Tester.to ( -50.999845 ), '-51' );
});

test( "Testing mark and thousand with longer strings", function(){

var Tester = wNumb({
Expand Down Expand Up @@ -131,7 +140,7 @@
test( "Testing edit, undo", function(){

var Tester = wNumb({
edit: function( value, originalValue ){
edit: function( value, originalValue ){
if ( originalValue > 100000 ) {
return value + 'm';
} else if ( originalValue > 1000 ) {
Expand All @@ -147,7 +156,7 @@

equal ( Tester.to ( 15000 ), '15000k' );
equal ( Tester.from ( '15000k' ), 15000 );

equal ( Tester.to ( 180 ), '180' );
equal ( Tester.from ( '180' ), 180 );

Expand Down
10 changes: 8 additions & 2 deletions wNumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var
}

// Reduce the number of decimals to the specified option.
if ( decimals ) {
if ( decimals !== false ) {
input = toFixed( input, decimals );
}

Expand Down Expand Up @@ -248,21 +248,27 @@ var

// Floating points in JS are stable up to 7 decimals.
} else if ( optionName === 'decimals' ) {
if ( optionValue > 0 && optionValue < 8 ) {
if ( optionValue >= 0 && optionValue < 8 ) {
filteredOptions[optionName] = optionValue;
} else {
throw new Error(optionName);
}

// These options, when provided, must be functions.
} else if ( optionName === 'encoder' || optionName === 'decoder' || optionName === 'edit' || optionName === 'undo' ) {
if ( typeof optionValue === 'function' ) {
filteredOptions[optionName] = optionValue;
} else {
throw new Error(optionName);
}

// Other options are strings.
} else {

if ( typeof optionValue === 'string' ) {
filteredOptions[optionName] = optionValue;
} else {
throw new Error(optionName);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions wNumb.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a5e1bb

Please sign in to comment.