+ 1
How can I round a double to 2 decimal points? (Swift)
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(String(Int(quarters)) + " quarters"); } return changeDue } let changedue = 0.52; let changeDue = quarters(changeDue:changedue); print(String(changeDue) + " remain"); I'm trying to round (up) so that the output for "changeDue" is a two-decimal point double
1 Resposta
+ 4
K G here is a simple method that I use but there are other methods
https://code.sololearn.com/cBBaK76pZotg/?ref=app