How to convert double to int in swift

后端 未结 8 1746
别跟我提以往
别跟我提以往 2020-12-24 10:30

So I\'m trying to figure out how I can get my program to lose the .0 after an integer when I don\'t need the any decimal places.

@IBOutlet weak var numberOf         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 10:49

    You can use:

    Int(yourDoubleValue)
    

    this will convert double to int.

    or when you use String format use 0 instead of 1:

    String(format: "%.0f", yourDoubleValue)
    

    this will just display your Double value with no decimal places, without converted it to int.

提交回复
热议问题