swift中double的错误值

时间:2016-04-19 06:16:41

标签: ios swift double add

我有字符串值并转换为double值以添加它。但它在调试时显示不同的值。在使用print语句时它显示正确的值,但是当在控制台中使用“po”命令显示不同时,所以获得不同的结果然后预期一个。

    let stringValue = "83.84"
    let doubleValue = Double(stringValue)
    let floatValue = Float(stringValue)

    let decimalArray: Array<Double> = [doubleValue!, doubleValue!, doubleValue!]
    let test1 = decimalArray.reduce(0, combine: +)

    let floatArray: Array<Float> = [floatValue!, floatValue!, floatValue!]
    let test2 = floatArray.reduce(0, combine: +)

    print(test1)
    print(test2)

我附上了控制台的图像。请让我知道如何解决这个问题。 enter image description here

1 个答案:

答案 0 :(得分:0)

我认为您在正确转换之前使用的是po。只在最后一行breakpoint放置print(test2),然后检查。