Round不接受参数类型(Int)

时间:2015-07-14 10:03:07

标签: swift uint32

当我来到分部时,我试图创建关于数学测试​​的应用程序。我知道我不能创建重复的无限小数,我必须保持数字随机。所以在我用arc4random_uniform生成数字之后,我试图使用round函数。但它说

  

无法为接受参数类型(Int)的圆形找到重载

我该如何解决这个问题?

这是我的代码:

 var randomNumber:UInt32 = arc4random_uniform(999)
 var randomNumber2:UInt32 = arc4random_uniform(999)
 // 1000 is my maximum number for now.
 randomNumber += 1
 randomNumber2 += 1
 if operation.text == "/" {
     if randomNumber < randomNumber2 {
         var between:UInt32 = 1000 - randomNumber2
         randomNumber = randomNumber2 + arc4random_uniform(between - 1)
         // making sure that randomNumber is not smaller than randomNumber2,
         // therefore all results are positive.
     }
     var answer:Int = round(Int(randomNumber)/Int(randomNumber2))
 }

1 个答案:

答案 0 :(得分:0)

您必须将Float值传递给round,因为它没有使用Int值的原型:

var answer = round(Float(randomNumber)/Float(randomNumber2))