Use a format string to round up to two decimal places and convert the double to a String:

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

Example:

let myDouble = 3.141
let doubleStr = String(format: "%.2f", myDouble) // "3.14"

If you want to round up your last decimal place, you could do something like this (thanks Phoen1xUK):

let myDouble = 3.141
let doubleStr = String(format: "%.2f", ceil(myDouble*100)/100) // "3.15"
Answer from JAL on Stack Overflow
🌐
Advanced Swift
advancedswift.com › rounding-floats-and-doubles-in-swift
Rounding Floats and Doubles in Swift
May 28, 2024 - Rounding 2 Decimal Places (Hundredths) ... Using floor · When using Swift for macOS and iOS apps, round(_:) is a built-in function able to accept a Double or a Float....
Discussions

Rounding a double value to x number of decimal places in swift - Stack Overflow
Can anyone tell me how to round a double value to x number of decimal places in Swift? I have: var totalWorkTimeInHours = (totalWorkTime/60/60) With totalWorkTime being an NSTimeInterval (double... More on stackoverflow.com
🌐 stackoverflow.com
Rounding Float to two decimal places - Using Swift - Swift Forums
I have a float value that detriments by 1.0, but the output can be 59.999, or 69.99998 at times and so I don't get round numbers like 60, 70, 80... I have a workaround, but I would like to know if there is a more elegan… More on forums.swift.org
🌐 forums.swift.org
0
August 14, 2019
swift - Round up double to 2 decimal places - Stack Overflow
It all depends on your needs, but it is certainly important to have a thorough understanding of data types such as Double(IEEE754) and Decimal, rounding rules FloatingPointRoundingRule, NSDecimalNumber.RoundingMode, NumberFormatter which can also be useful when working with currencies. More on stackoverflow.com
🌐 stackoverflow.com
iphone - Round double value to 2 decimal places - Stack Overflow
I have a double value as 22.368511 I want to round it to 2 decimal places. i.e. it should return 22.37 How can I do that? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Swift Forums
forums.swift.org › using swift › rounding float to two decimal places
Rounding Float to two decimal places - Using Swift - Swift Forums
August 14, 2019 - I have a workaround, but I would ... let numberOfPlaces = 2.0 let multiplier = pow(10.0, numberOfPlaces) let rounded = round(Double(totalYield) * m......
🌐
Medium
medium.com › @amrangry › rounding-numbers-in-swift-afb0de30ea85
Rounding Numbers in Swift. Rounding in Swift | by Amr Ahmed Elghadban | Medium
February 20, 2023 - In the second example, 15.1 is divided by ten (1.51), rounded (2.0), converted to an integer (2) and multiplied by 10 again (20). That’s it! By using round(_:), ceil(_:), and floor(_:) you can round Double and Float values to any number of ...
🌐
Code Ease
codeease.net › programming › swift › swift-round-double-to-2-decimal-places
swift round double to 2 decimal places | Code Ease
To round a double to 2 decimal places in Swift, you can use the rounded() method along with specifying the desired number of decimal places.
Find elsewhere
🌐
Uraimo
uraimo.com › swiftbites › rounding-doubles-to-specific-decimal-places
#15: Rounding Floating Point Numbers to Specific Decimal Places - uraimo.com
As described in this post, since Swift 3.0 is now possible to round floating point numbers through new methods added to the Double and Float types. But what about rounding a number to a specific number of decimal positions?
🌐
Codemia
codemia.io › home › knowledge hub › rounding a double value to x number of decimal places in swift
Rounding a double value to x number of decimal places in swift | Codemia
September 23, 2025 - Swift doesn't provide a direct method for rounding Double to a fixed number of decimal places, but various techniques can accomplish this effectively. The NumberFormatter class is a high-level approach for rounding and formatting numbers. It's suitable for formatting numbers for display, applying ...
🌐
sqlpey
sqlpey.com › swift › wift-double-rounding-techniques
Rounding a double value to x number of decimal places in swift
November 4, 2025 - extension Double { /// Rounds the double to a specified number of decimal places (Swift 2 style).
🌐
Devgex
devgex.com › en › article › 00005628
Complete Guide to Rounding Double Values to Specific Decimal Places in Swift - DevGex
November 10, 2025 - Swift's Double type follows the IEEE 754 standard, using binary floating-point representation. This means some decimal fractions cannot be precisely represented with finite binary fractions, leading to precision loss. For example, the decimal fraction 0.1 is a repeating fraction in binary, similar to how 1/3 is repeating in decimal. This representation limitation makes direct decimal place rounding of floating-point numbers complex, requiring specific algorithms to handle properly.
🌐
Sololearn
sololearn.com › en › Discuss › 2605494 › how-can-i-round-a-double-to-2-decimal-points-swift
How can I round a double to 2 decimal points? (Swift) | Sololearn: Learn to code for FREE!
November 28, 2020 - Here's the code: func quarters(changeDue:Double) -> Double { var quarters = (changeDue/0.25).rounded(.down); let changeDue = changeDue - (quarters * 0.25); if quarters == 1.0 { print(String(Int(quarters)) + " quarter"); } else { print(Strin...
🌐
Hacking with Swift
hackingwithswift.com › example-code › strings › how-to-specify-floating-point-precision-in-a-string
How to specify floating-point precision in a string - free Swift example code and tips
June 1, 2019 - But if you wanted to round the angle to two decimal places, you would use this code instead: let formatted = String(format: "Angle: %.2f", angle) The "%f" format string means "a floating point number," but "%.2f" means "a floating-point number ...
🌐
Global Nerdy
globalnerdy.com › home › better to be roughly right than precisely wrong: rounding numbers with swift
Better to be roughly right than precisely wrong: Rounding numbers with Swift : Global Nerdy
December 19, 2016 - Swift comes built-in with most of the rounding functions in C’s math library. The ones you’re most likely to use are round, floor, and ceil: ... A version that accepts a Double argument and returns a Double result (Doubles are 64-bit numbers and have a precision of at least 15 decimal digits), and