mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-05 22:07:10 -04:00
feat(new-tool): math evaluator
This commit is contained in:
parent
8fb0e6af9c
commit
433ba2a3e5
3 changed files with 83 additions and 0 deletions
38
src/tools/math-evaluator/math-evaluator.vue
Normal file
38
src/tools/math-evaluator/math-evaluator.vue
Normal file
|
@ -0,0 +1,38 @@
|
|||
<template>
|
||||
<div>
|
||||
<n-input
|
||||
v-model:value="expression"
|
||||
rows="1"
|
||||
type="textarea"
|
||||
placeholder="Your math expression (ex: 2*sqrt(6) )..."
|
||||
size="large"
|
||||
autocomplete="off"
|
||||
autocorrect="off"
|
||||
autocapitalize="off"
|
||||
spellcheck="false"
|
||||
/>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<n-card v-if="result !== ''" title="Result ">
|
||||
{{ result }}
|
||||
</n-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { evaluate } from 'mathjs';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
const expression = ref('');
|
||||
|
||||
const result = computed(() => {
|
||||
try {
|
||||
return evaluate(expression.value) ?? '';
|
||||
} catch (_) {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
Loading…
Add table
Add a link
Reference in a new issue