docs: add formula calculation documentation
parent
1827cdb592
commit
f023e01c6c
|
@ -0,0 +1,42 @@
|
|||
## Formula Calculation
|
||||
|
||||
### Instalation
|
||||
```
|
||||
yarn add mathjs algebra.js
|
||||
```
|
||||
|
||||
|
||||
### Example
|
||||
```ts
|
||||
import * as math from 'mathjs'
|
||||
import { Equation, parse } from 'algebra.js'
|
||||
|
||||
const formula = 'dpp - (dpp*ppn) - (dpp*retribusi) - (dpp*service) - (dpp*ppn3)'
|
||||
const total = '300000'
|
||||
|
||||
const variable = {
|
||||
ppn: 11,
|
||||
retribusi: 5000,
|
||||
service: 5,
|
||||
ppn3: 5000
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const x1 = math.simplify(formula, variable).toString()
|
||||
console.log('Formula ', x1)
|
||||
const dppFormula = parse(x1)
|
||||
const totalFormula = parse(total)
|
||||
const equation = new Equation(totalFormula, dppFormula)
|
||||
|
||||
console.log(equation.toString())
|
||||
const result = equation.solveFor('dpp').toString()
|
||||
console.log(result)
|
||||
|
||||
const value = math.evaluate(result)
|
||||
console.log(value)
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue