Skip to content

Instantly share code, notes, and snippets.

@iamchiwon
Created December 5, 2022 08:50
Show Gist options
  • Save iamchiwon/50937bc8043f9a027b38f22dce4bc067 to your computer and use it in GitHub Desktop.
Save iamchiwon/50937bc8043f9a027b38f22dce4bc067 to your computer and use it in GitHub Desktop.
import Foundation
extension Int {
public func decimal() -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = NumberFormatter.Style.decimal
return numberFormatter.string(from: NSNumber(value: self))!
}
public func currencyKRW() -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .currency
numberFormatter.locale = Locale(identifier: "ko_KR")
return numberFormatter.string(from: NSNumber(value: self))!
}
}
extension Float {
public func decimal() -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = NumberFormatter.Style.decimal
return numberFormatter.string(from: NSNumber(value: self))!
}
public func currencyKRW() -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .currency
numberFormatter.locale = Locale(identifier: "ko_KR")
return numberFormatter.string(from: NSNumber(value: self))!
}
}
extension FloatingPoint {
public var degreesToRadians: Self { return self * .pi / 180 }
public var radiansToDegrees: Self { return self * 180 / .pi }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment