From 160f1ebd9f0851db75e587b8076be426bf7e6915 Mon Sep 17 00:00:00 2001 From: Pin Lin Date: Wed, 6 May 2020 06:41:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=A6=E4=BD=9C=E6=8C=89=E4=B8=8B=20.=20?= =?UTF-8?q?=E8=A6=81=E6=80=8E=E9=BA=BC=E8=99=95=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidCalculator/Calculator.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AndroidCalculator/Calculator.swift b/AndroidCalculator/Calculator.swift index 8fa20b4..0da621c 100644 --- a/AndroidCalculator/Calculator.swift +++ b/AndroidCalculator/Calculator.swift @@ -47,6 +47,15 @@ class Calculator { formula.append(formula.popLast()! + text) } + case ".": + if formula.last!.firstIndex(of: ".") != nil { + return + } else if ["+", "-", "×", "÷"].firstIndex(of: formula.last!) != nil { + return + } else { + formula.append(formula.popLast()! + text) + } + default: print(formula) }