#13換算 App,匯率

很愛去日本旅行,但每次去的時候都會要拿出計算機換算台幣

刷卡的時候也不知道當下的金額是多少

想說就做一個app,下次去日本時候用得到

每家信用卡優惠不同,所以給大家自行填寫

手續費 大部分都是1.5% 所以直接預設好

當日匯率 以現在的匯率來算,希望以後學到抓取網路匯率的方法再來優化這個app

在button的IBAction裡設定金額和優惠的TextField 字串轉數字

let yenText = yenTextField.text!let discountText = discountTextField.text!let yen = Double(yenText)let discount = Double(discountText)

用if 判斷 TextField 的值不等於nil 然後來計算裡面的內容

在把數字轉字串取小數點第二位顯示出來

if yen != nil, discountTextField != nil {let twd = yen! * ratelet fee = twd * cardFeelet count = twd * discount! / 100let total = twd + fee - counttwdLabel.text = String(format: "%.2f", twd)feeLabel.text = String(format: "%.2f", fee)bonusLabel.text = String(format: "%.2f", count)totalLabel.text = String(format: "%.2f", total)view.endEditing(true)}

最後附上我的GitHub: https://github.com/kaikai215/exchangerate13

--

--