decimal - 声明 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"
解决方案
推荐阅读
- pact - 如何为单个字符串体定义契约规范匹配规则?
- sql - 'where-in' 子句中的强制条件匹配
- css - 将下拉菜单宽度扩展到父 div 宽度
- php - 处理企业 Web 应用程序中的计划/时间限制任务
- javascript - 中间日期有假期时如何计算持续时间
- drools - Drools - 为按消费者排名的产品表查找单个匹配条件
- diagram - 通过拖动自动连接 mxgraph 中的元素
- laravel - 如何解决“Facebook 检测到 MyApp 未使用安全连接传输信息。” Laravel 中的错误
- javascript - 如何读取 $_POST 中针对一个参数以表单数据发送的多个值
- batch-file - 检查bat中是否存在函数