Skip to content

Commit 5040a1f

Browse files
committed
fininshed dot function
1 parent ba23d77 commit 5040a1f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/components/Calculator.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="btn" @click="append('3')">3</div>
2020
<div class="btn operator" @click="plus">+</div>
2121
<div class="btn zero" @click="append('0')">0</div>
22-
<div class="btn">.</div>
22+
<div class="btn" @click="dot">.</div>
2323
<div class="btn operator" @click="equal">=</div>
2424
</div>
2525
</div>
@@ -83,8 +83,8 @@ export default {
8383
},
8484
equal() {
8585
this.current = `${this.operator(
86-
parseInt(this.current),
87-
parseInt(this.previous)
86+
parseFloat(this.current),
87+
parseFloat(this.previous)
8888
)}`;
8989
this.operator = null;
9090
this.operatorClicked = false;
@@ -100,6 +100,11 @@ export default {
100100
divide() {
101101
this.operator = (a, b) => a / b;
102102
this.setPrevious();
103+
},
104+
dot() {
105+
if (this.current.indexOf(".") === -1) {
106+
this.append(".");
107+
}
103108
}
104109
}
105110
};

0 commit comments

Comments
 (0)