Skip to content

Commit

Permalink
consider using first argument as number precision
Browse files Browse the repository at this point in the history
currently it is decimal offset
  • Loading branch information
defunctzombie committed Mar 16, 2013
1 parent 0a55466 commit 214d0b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion num.js
Expand Up @@ -12,6 +12,12 @@ function Num(num, prec) {
return self;
}

if (num instanceof int) {
this._int = num;
this._precision = prec || 0;
return self;
}

// convert to a string
num = '' + num;

Expand All @@ -28,7 +34,11 @@ function Num(num, prec) {
}

this._int = int(num);
this._precision = prec || precision;
this._precision = precision;

if (prec && prec > 0) {
this.set_precision(prec);
}
}

// TODO (shtylman) cleanup
Expand Down
6 changes: 3 additions & 3 deletions test/build.js
Expand Up @@ -36,8 +36,8 @@ test('build', function() {
});

test('build#precision', function() {
assert.equal(num(15, 1), '1.5');
assert.equal(num(1234567890, 5), '12345.67890');
assert.equal(num(-122, 4), '-0.0122');
assert.equal(num(15, 1), '15.0');
assert.equal(num(1234567890, 5).div(10e4), '12345.67890');
assert.equal(num(-122, 4).div(10e3), '-0.0122');
});

0 comments on commit 214d0b4

Please sign in to comment.