Answer the question
In order to leave comments, you need to log in
How to output number to console without .0?
Hello!
I use Xcode 9.4.1, Playground, Swift 4
Task example:
var a, b, c : Double
c = a/b // с = 10.0 / 2.0 = 5.0
print("Осталось \(c) яблок") // Осталось 5.0 яблок
Answer the question
In order to leave comments, you need to log in
extension Double
{
func truncate(places : Int)-> Double
{
return Double(floor(pow(10.0, Double(places)) * self)/pow(10.0, Double(places)))
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question