[Swift-devel] Formatting floats

Justin M Wozniak wozniak at mcs.anl.gov
Thu Apr 4 17:48:54 CDT 2013


The current function does not do this.  My thought was it is good to be 
able to represent Swift-specific types.  But it would also be good to 
have a function that simply uses Java's String.format().

On 04/04/2013 05:41 PM, David Kelly wrote:
> Hello,
>
> Is it possible to format floats in a printf() like way in Swift? I 
> tried using @sprintf to print to two decimal places, but it doesn't 
> seem to do what I want:
>
> float f=0.0;
> string s = @sprintf("%.2f", f);
>
> Execution failed:
> tracef(): Unknown format: %.
> swiftscript:sprintf, test.swift, line 2
> assignment, test.swift, line 3
>
> David
>
>
> _______________________________________________
> Swift-devel mailing list
> Swift-devel at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel


-- 
Justin M Wozniak

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20130404/bbd24704/attachment.html>


More information about the Swift-devel mailing list