There is a number 0.5. How to display it as 0.500000 swift generally allows you to do this? when I bring the number to Float still does not work

    2 answers 2

    See here .

    print(NSString(format: "%.6f", 0.5)) // 0.500000 
    • Thanks for the answer, and without import UIKit can no longer? - DmitrievichR
    • Formatting anyway assumes to translate in line in a similar way. - user207618 5:14
    • I understood here just on hackerrank.com/challenges/plus-minus there in the task it is written what is needed in the output 0.500000 I can’t import there - DmitrievichR
    • God, I blunted so sorry all ok, it requires zeros, thanks a lot for the answer! - DmitrievichR

    If you represent a number as a string, you can display it as

     func roundToPlaces(places:Float){ let aStr = String(format: "%05.6f", places) print(aStr) } print(roundToPlaces(0.5))