Home > Software design >  Firebase addition, subtraction, multiplication and division
Firebase addition, subtraction, multiplication and division

Time:10-05

I want to multiply the two firebase values ​​and get the result to display in the Label, without success Can anyone give me some advice

 func UserInfo(){
        let firestoreDB = Firestore.firestore()

        firestoreDB.collection("Usermoney").whereField("email", isEqualTo: Auth.auth().currentUser!.email!).addSnapshotListener { snapshot, error in
            if error != nil {
                print(error?.localizedDescription ?? "Error while getting data from server!" )
            }else{
                if snapshot?.isEmpty != true && snapshot != nil {
                    
                    for document in snapshot!.documents{
                        if let money = document.get("money") as? String{

                                    if let q8 = document.get("q8") as? String{
                                        
                                        self.money.text = money
                                
                                        self.q8.text = " " q8 "%"
                                       let tip = money * q8
                                        self.win.text = String(format: "$%.2f", tip)
                            }
                                }
                            }
                        }
                    }
                    
                }
            }

CodePudding user response:

Try This

func UserInfo(){
let firestoreDB = Firestore.firestore()

firestoreDB.collection("Usermoney").whereField("email", isEqualTo: Auth.auth().currentUser!.email!).addSnapshotListener { snapshot, error in
    if error != nil {
        print(error?.localizedDescription ?? "Error while getting data from server!" )
    }else{
        if snapshot?.isEmpty != true && snapshot != nil {
            
            for document in snapshot!.documents{
                if let money = document.get("money") as? String{
                    
                    if let q8 = document.get("q8") as? String{
                        
                        self.money.text = money
                        
                        self.q8.text = " " q8 "%"
                        if let moneyDouble = Double(money), let q8Double = Double(q8){
                            let tip = moneyDouble * q8Double
                            self.win.text = String(format: "$%.2f", tip)
                        }
                        
                    }
                }
            }
        }
    }
    
}

}

  • Related