How to print formated "%.9f" Double? Swift 2.2 ?


(Isaac Gouy) #1

I've tried various things from SO but none of them seem to work with Swift 2.2 on Ubuntu.


(Gage Morgan) #2

You mean .so files? Yeah, Cairo does not work with it either.

···

Sent from Outlook Mobile

On Thu, Dec 10, 2015 at 12:41 PM -0800, "Isaac Gouy via swift-users" <swift-users@swift.org> wrote:

I've tried various things from SO but none of them seem to work with Swift 2.2 on Ubuntu.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Isaac Gouy) #3

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


(Mish Awadah) #4

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

···

On Dec 10, 2015, at 1:50 PM, Harlan Haskins via swift-users <swift-users@swift.org> wrote:

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@swift.org <mailto:swift-users@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@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Harlan Haskins) #5

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 think variadic functions aren’t implemented in the dev version of Swift?

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Johan K. Jensen) #6

He probably means Stack Overflow <https://stackoverflow.com>.

···

On Thu, Dec 10, 2015 at 10:38 PM, Gage Morgan via swift-users < swift-users@swift.org> wrote:

You mean .so files? Yeah, Cairo does not work with it either.

Sent from Outlook Mobile <https://aka.ms/qtex0l>

On Thu, Dec 10, 2015 at 12:41 PM -0800, "Isaac Gouy via swift-users" < > swift-users@swift.org> wrote:

I've tried various things from SO but none of them seem to work with Swift
2.2 on Ubuntu.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Brent Royal-Gordon) #7

Variadic methods don't work on Linux yet: https://swift.org/blog/swift-linux-port/ I'm sure it's being worked on.

···

Sent from my iPad

On Dec 10, 2015, at 1:42 PM, Johan Jensen via swift-users <swift-users@swift.org> wrote:

He probably means Stack Overflow.

On Thu, Dec 10, 2015 at 10:38 PM, Gage Morgan via swift-users <swift-users@swift.org> wrote:
You mean .so files? Yeah, Cairo does not work with it either.

Sent from Outlook Mobile

On Thu, Dec 10, 2015 at 12:41 PM -0800, "Isaac Gouy via swift-users" <swift-users@swift.org> wrote:

I've tried various things from SO but none of them seem to work with Swift 2.2 on Ubuntu.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Isaac Gouy) #8

iirc I also tried to find a function that would round to 9 places, but this didn't seem to be available ?

    func round(value: Float, decimalPlaces: UInt)

···

On Thursday, December 10, 2015 1:58 PM, Brent Royal-Gordon via swift-users <swift-users@swift.org> wrote:

Variadic methods don't work on Linux yet: https://swift.org/blog/swift-linux-port/ I'm sure it's being worked on.