Не получается решить проблему с плавающей точкой
Не получается решить проблему с плавающей точкой (Делал и toFixed и Math.floor ничего не помогает.
const app = Vue.createApp({
data() {
return {
result: '',
numbers: ['*', '/', '-', 9, 8, 7, '+', 6, 5, 4, '%', 3, 2, 1, 0, '.'],
};
},
methods: {
displayItem: function (number) {
this.result += number;
},
clear: function () {
this.result = '';
},
calc: function () {
this.result = eval(this.result.toFixed());
},
},
}).mount('#app');
.calculator {
margin: 100px auto;
max-width: 300px;
background-color: #233446;
color: #fff;
padding: 15px;
box-shadow: 5px black;
user-select: none;
}
.wrapper-item{
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: 10px;
}
.item{
grid-column: 25%;
padding: 15px;
color: #fff;
font-size: 26px;
border: none;
background-color: #31455e;
cursor: pointer;
}
.item:hover{
background-color: #40b785;
}
.input{
grid-column: 1/ -1;
height: 50px;
background-color: #31455e;
text-align: right;
outline: none;
font-size: 26px;
color: #fff;
}
::placeholder{
font-size: 26px;
color: #fff;
padding-right: 5px;
}
.equally{
grid-column: 2/-1;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>calculator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id='app'>
<div class="calculator">
<div class="wrapper-item">
<input class="input" name="input" type="text" placeholder="0" readonly v-model='result'>
<button class="item" @click="clear()">C</button>
<button class="item" v-for="num of numbers" @click="displayItem(num)">{{num}}</button>
<button class="item equally" @click="calc()">=</button>
</div>
</div>
</div>
<script src="https://unpkg.com/vue@next"></script>
<script src="main.js"></script>
</body>
</html>