Skip to content

Commit a1df094

Browse files
committed
Fix round() API to use string parameter, not options object
The spec defines round() as: round(numFractionalDigits, roundingMode) where roundingMode is a string, not an options object. Changed all examples from: value.round(2, { roundingMode: "floor" }) to: value.round(2, "floor") This matches both the spec and the polyfill implementation.
1 parent d1a390a commit a1df094

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

docs/cookbook.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function splitBill(totalAmount, numberOfPeople) {
6767
const perPerson = total.divide(people);
6868

6969
// Round down to cents for most people
70-
const roundedPerPerson = perPerson.round(2, { roundingMode: "floor" });
70+
const roundedPerPerson = perPerson.round(2, "floor");
7171

7272
// Last person pays the remainder to ensure exact total
7373
const lastPersonPays = total.subtract(
@@ -361,21 +361,21 @@ const value = new Decimal("123.456");
361361
console.log(value.round(2).toString()); // => "123.46"
362362

363363
// Always round up (ceiling)
364-
console.log(value.round(2, { roundingMode: "ceil" }).toString()); // => "123.46"
364+
console.log(value.round(2, "ceil").toString()); // => "123.46"
365365

366366
// Always round down (floor)
367-
console.log(value.round(2, { roundingMode: "floor" }).toString()); // => "123.45"
367+
console.log(value.round(2, "floor").toString()); // => "123.45"
368368

369369
// Round towards zero (truncate)
370-
console.log(value.round(2, { roundingMode: "trunc" }).toString()); // => "123.45"
370+
console.log(value.round(2, "trunc").toString()); // => "123.45"
371371

372372
// Round half away from zero
373-
console.log(value.round(2, { roundingMode: "halfExpand" }).toString()); // => "123.46"
373+
console.log(value.round(2, "halfExpand").toString()); // => "123.46"
374374

375375
// Negative number example
376376
const negative = new Decimal("-123.456");
377-
console.log(negative.round(2, { roundingMode: "floor" }).toString()); // => "-123.46"
378-
console.log(negative.round(2, { roundingMode: "ceil" }).toString()); // => "-123.45"
377+
console.log(negative.round(2, "floor").toString()); // => "-123.46"
378+
console.log(negative.round(2, "ceil").toString()); // => "-123.45"
379379
```
380380

381381
### Financial rounding

docs/decimal.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,20 @@ new Decimal("-123.45").negate().toString(); // => "123.45"
195195

196196
All rounding methods follow IEEE 754-2019 rounding modes.
197197

198-
### **round**(_scale_?: number, _options_?: { roundingMode?: string }) : Decimal
198+
### **round**(_scale_?: number, _roundingMode_?: string) : Decimal
199199

200200
Rounds to a given number of decimal places.
201201

202202
**Parameters:**
203203

204204
- `scale` (number): Number of decimal places to round to (default: 0)
205-
- `options.roundingMode` (string): One of "ceil", "floor", "trunc", "halfEven" (default), or "halfExpand"
205+
- `roundingMode` (string): One of "ceil", "floor", "trunc", "halfEven" (default), or "halfExpand"
206206

207207
```js
208208
const d = new Decimal("123.456");
209209
d.round().toString(); // => "123"
210210
d.round(2).toString(); // => "123.46"
211-
d.round(2, { roundingMode: "floor" }).toString(); // => "123.45"
211+
d.round(2, "floor").toString(); // => "123.45"
212212
```
213213

214214
## Comparison Methods

0 commit comments

Comments
 (0)