Created
August 27, 2016 11:10
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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