Skip to content

Commit d109f95

Browse files
author
Samori Gorse
committed
Fixed bug with substr on IE
Added html test runner
1 parent 107a410 commit d109f95

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

decimaljs.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ Decimal.prototype.add = function(target) {
5151

5252
var fst = Decimal._format(ops[1].repr.value, biggest - tiniest) * 1;
5353
var snd = ops[0].repr.value * 1;
54+
5455
var calc = String(fst + snd);
55-
56-
56+
5757
return Decimal._format(calc, tiniest);
5858
}
5959

@@ -85,10 +85,12 @@ Decimal._neg_exp = function(str, position) {
8585

8686
if(offset >= 0) {
8787
str = Decimal.__zero(offset) + str;
88-
sep = 0 + '.';
88+
sep = '0.';
8989
}
90+
91+
var length = str.length;
9092

91-
return str.substr(0, str.length - position) + sep + str.substr(-position);
93+
return str.substr(0, length - position) + sep + str.substring(length - position, length);
9294
}
9395

9496
Decimal._pos_exp = function(str, exp) {

index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Test suite</title>
5+
</head>
6+
<body>
7+
<script>
8+
function print() {
9+
var args = arguments;
10+
11+
for(var i=0; i < args.length; i++) {
12+
document.write(args[i] + '<br>');
13+
}
14+
}
15+
16+
function load() {
17+
var args = arguments;
18+
19+
for(var i=0; i < args.length; i++) {
20+
var script = document.createElement('script');
21+
script.src = args[i];
22+
document.body.appendChild(script);
23+
}
24+
}
25+
</script>
26+
<script src="tests/runner.js"></script>
27+
</body>
28+
</html>

tests/.swp

-12 KB
Binary file not shown.

tests/runner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ load(
3030
'tests/subtraction.js'
3131
);
3232

33-
assert.summary();
33+
setTimeout(function() {
34+
assert.summary()
35+
}, 2000);

0 commit comments

Comments
 (0)