How to concatenate an integer variable with string variables

Hello:

 

I am using Swift 5.1.3. I can’t get a simple Int variable to concatenate with String variables.

Any help will be appreciated. I want to include a percentage from two numbers with a string of Strings. Belowis my code:

 

I am getting an error on line 12: Binary operator ‘+’ cannot be applied to operands of type ‘String’ and ‘Int’

referencing “groupPercent”

 

func getPercent(){
               
                let groupPercent: Double = Double(qmSum) / Double(qaSum) * 100
                
                 print ("Percent is (groupPercent)")
               
                 }
                getPercent()
               
                let firstPart = (groupNameItem) + (" ")
                let secondPart = ("Group Score") + (" ")
                let newLine = (firstPart + secondPart + groupPercent)
                studentsText?.string = studentsText!.string + newLine + "n"

 

Thanks.

Powered by WPeMatico

You may also like...

Comments are closed.