본문 바로가기

Programming/Swift

round number to 2 decimal places

let currentRatio = Double (rxCurrentTextField.text!)! / Double (txCurrentTextField.text!)! railRatioLabelField.text! = String(format: "%.2f", currentRatio)

 

 

Round up double to 2 decimal places

How do I round up currentRatio to two decimal places? let currentRatio = Double (rxCurrentTextField.text!)! / Double (txCurrentTextField.text!)! railRatioLabelField.text! = "\(currentRatio)"

stackoverflow.com