summaryrefslogtreecommitdiff
path: root/Utils/Double+truncate.swift
blob: b86d51d55d05ea6fec3889f72baefc0db1247571 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
//  Double+truncate.swift
//  PrySDR
//
//  Created by Jacky Jack on 23/01/2025.
//

import Foundation

extension Double {
    func truncate(places : Int)-> Double {
        return Double(floor(Foundation.pow(10.0, Double(places)) * self)/Foundation.pow(10.0, Double(places)))
    }
}

extension Float32 {
    func truncate(places : Int)-> Float32 {
        return Float32(floor(Foundation.pow(10.0, Float32(places)) * self)/Foundation.pow(10.0, Float32(places)))
    }
}

extension Float32 {
   var bytes: [UInt8] {
       withUnsafeBytes(of: self, Array.init)
   }
}