首页 > 解决方案 > 声明 Int 和用小数计算的问题

问题描述

首先,感谢您的帮助!我对编码相当陌生,并且在将小数输入文本字段时计算应用程序时遇到了麻烦。它允许整数没问题,但我希望能够输入小数。

谢谢!这是我到目前为止所拥有的。当我去计算分数时寻求帮助。使用 SwiftUI

@State var value1: String = ""
@State var value2: String = ""
@State var value3: String = ""
@State var score: String = ""
@State var scoredetail: String = ""



            VStack {
                TextField("Enter value1", text: $value1)
                    .keyboardType(.decimalPad)
                   

                TextField("Enter value2", text: $value2)
                   

                TextField("Enter value3", text: $value3)
                  




            VStack {
                Text(score)
                    
                Text(scoredetail)
                   


        }

        HStack {
            Button(action: {
                let value1 = Int(self.value1)
                let value2 = Int(self.value2)
                let value3 = Int(self.value3)
                                                    
                let finalscore = Int((value1! * value2!) / (value3!))
              
               
                self.score = "Your score is"
                if finalscore > 18{
                    self.scoredetail = "A+ Value"

标签: decimal

解决方案


推荐阅读