Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get 1 decimal Float in swift [duplicate]

I want to extract 1 decimal float number from existing float number.

I have done this in Objective-C: Make a float only show two decimal places

Any idea how to make it happen in Swift?

like image 786
aksani56 Avatar asked Dec 12 '22 05:12

aksani56


1 Answers

You can make the same in swift :

var formatter : NSString = NSString(format: "%.01f", myFloat)

Or like you want in one line :

println("Pro Forma:- \n Total Experience(In Years) = "+(NSString(format: "%.01f", myFloat)))

This work too with the old NSLog (but prefer println) :

NSLog("Pro Forma:- \n Total Experience(In Years) = %.01f \n", myFloat)
like image 74
jaumard Avatar answered Jan 11 '23 19:01

jaumard