[swift-users] How to print formated "%.9f" Double? Swift 2.2 ?

Mish Awadah mawadah at apple.com
Thu Dec 10 16:42:40 CST 2015


> On Dec 10, 2015, at 1:50 PM, Harlan Haskins via swift-users <swift-users at swift.org> wrote:
> 
> I’m not sure what happened to String(format:), but I haven’t been able to get it to work either.
> It’s printing its argument as a tuple.

I believe that String(format:) is implemented differently on Linux due to lack of ObjC/Foundation. This is a subtlety.

> 
> I think variadic functions aren’t implemented in the dev version of Swift?

Correct, vararg C functions don’t get imported into Swift.

- mish

> 
> main.swift:3:1: error: 'printf' is unavailable: Variadic function is unavailable
> printf("%0.2d", 4.555555555)
> ^~~~~~
> SwiftGlibc.printf:2:13: note: 'printf' has been explicitly marked unavailable here
> public func printf(__format: UnsafePointer<Int8>, _ varargs: Any...) -> Int32
> 
>> On Dec 10, 2015, at 4:39 PM, Isaac Gouy via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
>> 
>> 
>> For example,
>> 
>>   print( String(format: "%.3f", 1.23489) )
>> 
>>   $ /usr/local/src/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/bin/swiftc test.swift
>> 
>>   $ ./test
>>   ("%.3f", 1.23489)
>> 
>> Not 1.235
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org <mailto:swift-users at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151210/32a69fb6/attachment.html>


More information about the swift-users mailing list