Last active
July 26, 2023 07:06
-
-
Save Innovatewithapple/002a09e4345a028e31d1621668cd6443 to your computer and use it in GitHub Desktop.
Format Double or Float values without rounded. Use this method and set maximum decimals according to your need.
This file contains 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
func IWADoubleFormat(_ a: Double, max: Int) -> Double { | |
let stringArr = String(a).split(separator: ".") | |
let decimals = Array(stringArr[1]) | |
var string = "\(stringArr[0])." | |
var count = 0; | |
for n in decimals { | |
if count == max { break } | |
string += "\(n)" | |
count += 1 | |
} | |
let double = Double(string)! | |
return double | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment