Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 6dfc00a

Browse files
committed
Clean up examples
1 parent e5302ae commit 6dfc00a

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

examples/mortgage.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ const one = new Decimal128("1");
55
const paymentsPerYear = new Decimal128("12");
66

77
function calculateMonthlyPayment(p, r, y) {
8-
let principal = new Decimal128(p);
9-
let annualInterestRate = new Decimal128(r);
10-
let years = new Decimal128(y);
8+
const principal = new Decimal128(p);
9+
const annualInterestRate = new Decimal128(r);
10+
const years = new Decimal128(y);
1111
const monthlyInterestRate = annualInterestRate.divide(paymentsPerYear);
1212
const paymentCount = paymentsPerYear.multiply(years);
1313
const onePlusInterestRate = monthlyInterestRate.add(one);
1414
const ratePower = pow(onePlusInterestRate, paymentCount);
1515

16-
let x = principal.multiply(monthlyInterestRate);
17-
let numerator = x.multiply(ratePower);
16+
const x = principal.multiply(monthlyInterestRate);
1817

19-
let denominator = ratePower.subtract(one);
20-
21-
return numerator.divide(denominator);
18+
return x.multiply(ratePower).divide(ratePower.subtract(one));
2219
}
2320

2421
console.log(calculateMonthlyPayment("5000000", "0.05", "30").toString());

examples/step.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ function stepUp(d, n, x) {
1111

1212
let starting = new Decimal128("1.23");
1313
let stepped = stepUp(starting, new Decimal128("3"), new Decimal128("-4"));
14-
console.log(stepped.toString({ numDecimalDigits: 4 })); // 1.2305
14+
console.log(stepped.toString({ numFractionalDigits: 4 })); // 1.2305

0 commit comments

Comments
 (0)