help me, error during division please help me

I made a calculator in swift ui but the function I made for division works, but it doesn't work correctly, for example to make 25/2= 12.5 mine makes 25/2=12.0 so I round the result I put the function here Below if anyone can help me and write me the correct function, thank you very much in advance everyone :)

func buttonTapped(_ title: String) {
            if title == "%" {
                // Calcola la percentuale
                if let number = Double(displayText) {
                    let result = number / 100.0
                    displayText = String(result)
                    let fullOperation = "\(number)% = \(result)"
                            addToHistory(fullOperation)
                    
                } else if title == "/" {
                    // Calcola la divisione
                    let components = displayText.components(separatedBy: "/")
                    
                    if components.count == 2,
                       let numerator = Double(components[0]),
                       let denominator = Double(components[1]), denominator != 0 {
                        let result = numerator / denominator
                        displayText = String(result)
                        let fullOperation = "\(numerator) / \(denominator) = \(result)"
                        addToHistory(fullOperation)
                    } else {
                        // Gestisci la divisione per zero o formato non valido
                        displayText = "Errore"
                        addToHistory("Errore: Divisione non valida")
                    }
                } //fine divisione

It seems like the issue might be related to how the result is displayed after the division operation. If you want to display decimal places for the result, you can use the String(format:) method to format the result with a specific number of decimal places.

Here's how you can modify the division part of your code to ensure it displays the result with the correct decimal places:

    // Calcola la divisione
    let components = displayText.components(separatedBy: "/")

    if components.count == 2,
       let numerator = Double(components[0]),
       let denominator = Double(components[1]), denominator != 0 {
        let result = numerator / denominator
        displayText = String(format: "%.1f", result) // Use "%.1f" for one decimal place
        let fullOperation = "\(numerator) / \(denominator) = \(result)"
        addToHistory(fullOperation)
    } else {
        // Gestisci la divisione per zero o formato non valido
        displayText = "Errore"
        addToHistory("Errore: Divisione non valida")
    }
} //fine divisione

In the modified code, String(format: "%.1f", result) is used to format the result with one decimal place. Adjust the format string ("%.1f") according to the number of decimal places you want to display.

help me, error during division please help me
 
 
Q