NSLog()格式可以在Swift中超过八倍吗?

时间:2016-03-28 05:06:38

标签: swift number-formatting nslog

当我尝试在Swift的NSLog()中格式化超过八个双打时,前八个很好。剩余的双打经常错误地表示为0.0。偶尔,我会得到一个很长的数字,而不是0.0,而不是像

1143028425600163529287784455055173199670798747070639575063120152283070194166043387484791550160425300628149851402570478008077137648389330869144763352222012984900499165551916115751227038304582371235517382094416130757884235441564878725430349135872.000000

我为ios和os x看到了这个。

这是从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.000000 0.000000”结尾。这应该是“9.500000 10.500000”。使用%f或%。2lf而不是%lf似乎没有什么区别。

这是一个错误吗?

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

0 个答案:

没有答案