How to create a string with format?

后端 未结 12 1333
别跟我提以往
别跟我提以往 2020-11-30 18:13

I need to create a string with format which can convert int, long, double etc. types into string. Using Obj-C, I can do it via below way.

NSString *str = [NS         


        
12条回答
  •  野性不改
    2020-11-30 19:01

    First read Official documentation for Swift language.

    Answer should be

    var str = "\(INT_VALUE) , \(FLOAT_VALUE) , \(DOUBLE_VALUE), \(STRING_VALUE)"
    println(str)
    

    Here

    1) Any floating point value by default double

    EX.
     var myVal = 5.2 // its double by default;
    

    -> If you want to display floating point value then you need to explicitly define such like a

     EX.
         var myVal:Float = 5.2 // now its float value;
    

    This is far more clear.

提交回复
热议问题