DECIMAL arena

An example of how we can configure decimal.js to automatically round to the correct number of decimal places when JSON.stringify()-ed.

by Aswin Devarajan

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/decimal.js/10.0.0/decimal.min.js"></script>
<pre id="output"></pre>

JavaScript

let a = Decimal(71.2)
let b = Decimal(9)

let viva = Decimal(a).div(100)
let vida = Decimal(viva).mul(b).toFixed(2)
console.log(vida)

// console.log((a/100)*b)