📜  如何快速获取数字的位数 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:51:40.635000             🧑  作者: Mango

代码示例1
public extension Int {
/// returns number of digits in Int number
public var digitCount: Int {
    get {
        return numberOfDigits(in: self)
    }
}
/// returns number of useful digits in Int number
public var usefulDigitCount: Int {
    get {
        var count = 0
        for digitOrder in 0.. Int {
    if number < 10 && number >= 0 || number > -10 && number < 0 {
        return 1
    } else {
        return 1 + numberOfDigits(in: number/10)
    }
}
// returns true if digit is useful in respect to self
private func isUseful(_ digit: Int) -> Bool {
    return (digit != 0) && (self % digit == 0)
}