How to use the fraction function from mathjs

Find comprehensive JavaScript mathjs.fraction code examples handpicked from public code repositorys.

27
28
29
30
31
32
33
34
35
36
const roundNumber = (number = 0, decimals = 4) => {
    if (number === 0 || number === Infinity || isNaN(number)) {
        return 0;
    } else if (decimals > 0) {
        const multipliedNumber = math.multiply(
            math.fraction(number),
            math.pow(10, decimals)
        );
        const dividedNumber = math.divide(
            math.floor(multipliedNumber),
fork icon211
star icon236
watch icon0

318
319
320
321
322
323
324
325
326
327
    }catch (error){
        xSolution = "error"
    }


}while(xSolution === "error" || fraction(xSolution).n > fraction(xSolution).d || fraction(ySolution).n > fraction(ySolution).d || fraction(xSolution).n > maxNum/5 || fraction(xSolution).d > maxNum/5 || fraction(ySolution).n > maxNum/5 || fraction(ySolution).d > maxNum/5)

if(getRandomNum(0,1) === 1){
    expressionShown1 = isolated1
}else expressionShown1 = problem1.expression
fork icon0
star icon0
watch icon0

+ 13 other calls in file

111
112
113
114
115
116
117
118
119
120
#getAnswer() {
    let answer
    // Apply appropriate math operation.
    // Numbers converted to fractions to prevent JS floating point errors.
    const valueL = math.fraction(this.leftNum.value)
    const valueR = math.fraction(this.rightNum.value)
    if (this instanceof Plus) {
        answer = math.add(valueL, valueR)
    } else if (this instanceof Minus) {
        answer = math.subtract(valueL, valueR)
fork icon0
star icon0
watch icon0

+ 2 other calls in file