1 Vue project installation Decimal
npm install
2 Note
The result of the operation is a Decimal object, and you need to use .toNumber() to convert it to a number.
3 plus add
const Decimal = require('') const num1 = Decimal("5"); const num2 = Decimal("3"); const remainder = (num2);
4 minus sub
const Decimal = require('') const num1 = Decimal("5"); const num2 = Decimal("3"); const remainder = (num2);
5 by mul
const Decimal = require('') const num1 = Decimal("5"); const num2 = Decimal("3"); const remainder = (num2);
6 except div
const Decimal = require('') const num1 = Decimal("5"); const num2 = Decimal("3"); const remainder = (num2);
7 Find the rest module
const Decimal = require('') const num1 = Decimal("5"); const num2 = Decimal("3"); const remainder = (num2);
Appendix: Use vue to solve the problem of missing accuracy of total sum of decimals
- Installation dependencies
- npm install --save
- Package
- Create a file under the utils folder
import { Decimal } from '' export function add (x, y) { if (!x) { x = 0 } if (!y) { y = 0 } const xx = new Decimal(x) const yy = new Decimal(y) return (yy).toNumber() } // reduceexport function sub (x, y) { if (!x) { x = 0 } if (!y) { y = 0 } const xx = new Decimal(x) const yy = new Decimal(y) return (yy).toNumber() } // removeexport function div (x, y) { if (!x) { x = 0 } if (!y) { return 0 } const xx = new Decimal(x) const yy = new Decimal(y) return (yy).toNumber() } //takeexport function mul (x, y) { if (!x) { x = 0 } if (!y) { y = 0 } const xx = new Decimal(x) const yy = new Decimal(y) return (yy).toNumber() }
- Page usage
<script> import {add} from "@/utils/decimal" export default { methods:{ handlePlus() { add(10.5,4.877) } } } </script>
Summarize
This is the article about how to use the front-end vue project to calculate the remaining operation. This is the end of this article. For more related vue to calculate the remaining operation, please search for my previous articles or continue to browse the related articles below. I hope everyone will support me in the future!