How to use the minimum function from bignumber.js

Find comprehensive JavaScript bignumber.js.minimum code examples handpicked from public code repositorys.

bignumber.js.minimum is a function that returns the smaller of two BigNumber instances.

944
945
946
947
948
949
950
951
952
953
 * 返回给定键的最小值
 */
min(key) {
    // 获取值
    const nums = getNums.call(this, key)
    return nums.length ? BigNumber.minimum(...nums).toNumber() : 0
}

/**
 * 方法确定集合中是否存在给定键
fork icon0
star icon2
watch icon2

+ 8 other calls in file

How does bignumber.js.minimum work?

bignumber.js.minimum() is a static method in the BigNumber library that takes in two BigNumber instances or string values as arguments, compares their values and returns the minimum value. First, it checks the values for validity and sign. If any of them are invalid, it returns a new BigNumber instance with NaN. If the signs of the two numbers are different, it returns the number with the negative sign. If both the numbers have the same sign, it returns the smaller value of the two. The method is used for comparing and finding the minimum value between two numbers represented as BigNumber instances.

Ai Example

1
2
3
4
5
6
const BigNumber = require("bignumber.js");

const a = new BigNumber("0.1");
const b = new BigNumber("0.2");

console.log(BigNumber.minimum(a, b).toString()); // output: 0.1

In this example, we create two BigNumber instances a and b with values 0.1 and 0.2, respectively. We then pass them to the BigNumber.minimum function which returns the smaller of the two values, in this case a with a value of 0.1. The toString() method is called on the result to convert it to a string for output.