Last active
March 17, 2021 05:55
-
-
Save codewithsanthoshofficial/5b49a868921462857e8c9111d570aab9 to your computer and use it in GitHub Desktop.
DecimalsHandleSwift5KSK
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 Constant { | |
| static func twoDecimalValueReturnDouble(_ total:Double) -> Double { | |
| let val = String(format: "%.2f", total) | |
| let final = (val as NSString).doubleValue | |
| return final | |
| } | |
| static func twoDecimalValue(_ total:Double) -> String { | |
| return String(format: "%.2f", total) | |
| } | |
| static func convertStringToDouble(_ total:String) -> Double { | |
| let value = (total as NSString).doubleValue | |
| return value | |
| } | |
| static func singleOrRemoveDecimalValueString(_ total:String) -> String { | |
| let myFloat = (total as NSString).floatValue | |
| let intValue = Int(myFloat) | |
| if Float(intValue) < myFloat { | |
| return String(format: "%.2f", myFloat) | |
| } | |
| return String(format: "%.f", myFloat) | |
| } | |
| static func twoDecimalValueString(_ total:String) -> String { | |
| let myFloat = (total as NSString).floatValue | |
| return String(format: "%.2f", myFloat) | |
| } | |
| static func threeDecimalValueString(_ total:String) -> String { | |
| let myFloat = (total as NSString).floatValue | |
| return String(format: "%.3f", myFloat) | |
| } | |
| static func fourDecimalValueString(_ total:String) -> String { | |
| let myFloat = (total as NSString).floatValue | |
| return String(format: "%.4f", myFloat) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment