Home > AI > IOS > Foundation >

float to string


func float2str(value: Float, minDec: Int ) -> String {
    let formatter = NumberFormatter.init()
    formatter.maximumFractionDigits = 2
    formatter.minimumFractionDigits = minDec
    let str = formatter.string(from: NSNumber.init(value: value)) ?? "0"
    return str
}

Leave a Reply