//
//  BFFloat+Ext.swift
//  BFFramework
//
//  Created by ak on 2021/10/11.
//

import Foundation

extension Float {
    /// 准确的小数尾截取 - 没有进位
    /*
     // 11.999003  -> 12.0
     var pp = 11.999003
     String(format: "%.1f", pp)  这个方法会进行四舍五入
     */
    func decimalString(_ base: Self = 1) -> String {
       return "\(self.decimalNumber(base))"
    }
    func decimalNumber(_ base: Self = 1) -> Float {
        let tempCount: Self = pow(10, base)
        let temp = self*tempCount
        
        let target = Self(Int(temp))
        let stepone = target/tempCount
        if stepone.truncatingRemainder(dividingBy: 1) == 0 {
            return Float(String(format: "%.0f", stepone)) ?? 0.0
        }else{
            return stepone
        }
    }
}
 
