Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NSLog()能否在Swift中格式化八个以上的双精度?_Swift_Number Formatting_Nslog - Fatal编程技术网

NSLog()能否在Swift中格式化八个以上的双精度?

NSLog()能否在Swift中格式化八个以上的双精度?,swift,number-formatting,nslog,Swift,Number Formatting,Nslog,当我试图在Swift中的NSLog()中格式化八个以上的double时,前八个就可以了。剩下的双打经常错误地显示为0.0。偶尔,我会得到一个很长的数字,而不是0.0,比如 11430284256001635292877844550551731996707987470706395750631201522830701941660433874847915501604253006281498514025704780080771376483893308691447633522220129849004991

当我试图在Swift中的NSLog()中格式化八个以上的double时,前八个就可以了。剩下的双打经常错误地显示为0.0。偶尔,我会得到一个很长的数字,而不是0.0,比如

1143028425600163529287784455055173199670798747070639575063120152283070194166043387484791550160425300628149851402570478008077137648389330869144763352222012984900499165551916115751227038304582371235517382094416130757884235441564878725430349135872.000000
我在ios和OSX上看到了这一点

这是我从Xcode运行的main.swift:

import Foundation

let a : [Double] = (1...10).map({ 0.5 + Double($0) })
let b : [Int] = (1...10).map({ $0 })
NSLog("Ten doubles \(a)")
NSLog("Ten integers \(b)")
NSLog("Ten doubles again %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9])
NSLog("Ten integers again %d %d %d %d %d %d %d %d %d %d", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9])
以下是输出:

2016-03-27 21:52:47.676 testStuff[25971:6046917] Ten doubles [1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5]
2016-03-27 21:52:47.677 testStuff[25971:6046917] Ten integers [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
2016-03-27 21:52:47.677 testStuff[25971:6046917] Ten doubles again 1.500000 2.500000 3.500000 4.500000 5.500000 6.500000 7.500000 8.500000 0.000000 0.000000
2016-03-27 21:52:47.677 testStuff[25971:6046917] Ten integers again 1 2 3 4 5 6 7 8 9 10
奇怪的是上面的第三行输出以“0.0000000.000000”结尾。应该是“9.500000 10.500000”。使用%f或%.2lf而不是%lf似乎没有什么区别

这是虫子吗


我不需要解决办法。我只是想知道我是否遗漏了什么。

这对我来说绝对是个问题。同样的情况也发生在
let s1=String(格式:“%f%f%f%f%f%f%f%f”、a[0]、a[1]、a[2]、a[3]、a[4]、a[5]、a[6]、a[7]、a[8]、a[9]);打印(s1)
。谢谢,@MartinR。很高兴知道这是字符串格式化程序的一个更普遍的问题。