Skip to content

Instantly share code, notes, and snippets.

@omgbbqhaxx
Created August 27, 2016 11:10
Show Gist options
  • Select an option

  • Save omgbbqhaxx/ebf2bdf6db59a783ba115315ad829791 to your computer and use it in GitHub Desktop.

Select an option

Save omgbbqhaxx/ebf2bdf6db59a783ba115315ad829791 to your computer and use it in GitHub Desktop.
Eğer float'ta noktadan sonraki basamaklar zaten sıfırsa bunu gösterme fakat başka bir rakamsa göster.
extension Float {
var cleanValue: String {
return self % 1 == 0 ? String(format: "%.0f", self) : String(self)
}
}
Usage:
var sampleValue: Float = 3.234
print(sampleValue.cleanValue)
3.234
sampleValue = 3.0
print(sampleValue.cleanValue)
3
sampleValue = 3
print(sampleValue.cleanValue)
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment