Skip to content

Commit 481cf34

Browse files
committed
Added modulus feature #32
1 parent 7a8129d commit 481cf34

File tree

11 files changed

+1024
-403
lines changed

11 files changed

+1024
-403
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Travis](https://img.shields.io/travis/royNiladri/js-big-decimal.svg?style=flat-square)](https://travis-ci.org/royNiladri/js-big-decimal)
44
[![devDependencies Status](https://img.shields.io/david/dev/royNiladri/js-big-decimal.svg?style=flat-square)](https://david-dm.org/royNiladri/js-big-decimal?type=dev)
5-
![Coveralls](https://img.shields.io/coveralls/github/royNiladri/js-big-decimal/master)
5+
[![Coverage Status](https://img.shields.io/coveralls/github/royNiladri/js-big-decimal/master?style=flat-square)](https://coveralls.io/github/royNiladri/js-big-decimal?branch=master)
66
[![license](https://img.shields.io/github/license/royNiladri/js-big-decimal.svg?style=flat-square)](https://github.com/royNiladri/js-big-decimal/blob/master/LICENSE)
77
[![npm](https://img.shields.io/npm/v/js-big-decimal.svg?style=flat-square)](https://www.npmjs.com/package/js-big-decimal)
88
[![npm](https://img.shields.io/npm/dt/js-big-decimal.svg?style=flat-square)](https://www.npmjs.com/package/js-big-decimal)
@@ -29,6 +29,7 @@ Work with large numbers on the client side with high precision.
2929
- [subtract(minuend, subtrahend)](#subtractminuend-subtrahend)
3030
- [multiply(multiplicand, multiplier)](#multiplymultiplicand-multiplier)
3131
- [divide(dividend, divisor, precision)](#dividedividend-divisor-precision)
32+
- [modulus(dividend, divisor)](#modulusdividend-divisor)
3233

3334
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3435

@@ -215,11 +216,24 @@ var product = n1.multiply(n2); // product = new bigDecimal('-0.000169')
215216
### divide(dividend, divisor, precision)
216217
Divide two numbers. Pass arguments as `string` if calling on bigDecimal or pass an instance of bigDecimal if calling on object. `precision` is an optional parameter with default value of 8.
217218
```javascript
218-
var quotient = bigDecimal.divide('45', '4', 2); // quotient = 11.25
219+
var quotient = bigDecimal.divide('45', '4', 2); // quotient = '11.25'
219220
```
220221
Alternately, use the instance property. It returns the result as new `bigDecimal`.
221222
```javascript
222223
var n1 = new bigDecimal('45');
223224
var n2 = new bigDecimal('4');
224225
var quotient = n1.divide(n2); // quotient = new bigDecimal('11.25')
225226
```
227+
228+
### modulus(dividend, divisor)
229+
Get the modulus of two numbers, i.e., remainder when the dividend is divided by the divisor. Note that both divisor and dividend need to be integers.
230+
```javascript
231+
var remainder = bigDecimal.modulus('45', '4'); // remainder = '1'
232+
```
233+
Alternately, use the instance property. It returns the result as new `bigDecimal`.
234+
```javascript
235+
var n1 = new bigDecimal('45');
236+
var n2 = new bigDecimal('4');
237+
var remainder = n1.modulus(n2); // remainder = new bigDecimal('1')
238+
```
239+
Further, the result takes the sign of the dividend and the sign of the divisor is ignored. Note that this behaviour is the same as in Java and JavaScript.

dist/node/big-decimal.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ declare class bigDecimal {
2121
multiply(number: bigDecimal): bigDecimal;
2222
static divide(number1: any, number2: any, precision: any): string;
2323
divide(number: bigDecimal, precision: any): bigDecimal;
24+
static modulus(number1: any, number2: any): string;
25+
modulus(number: bigDecimal): bigDecimal;
2426
static compareTo(number1: any, number2: any): 0 | 1 | -1;
2527
compareTo(number: bigDecimal): 0 | 1 | -1;
2628
static negate(number: any): string;

0 commit comments

Comments
 (0)