-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber+Util.swift
More file actions
40 lines (33 loc) · 851 Bytes
/
Number+Util.swift
File metadata and controls
40 lines (33 loc) · 851 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Number+Util.swift
// cleaner
//
// Created by zy on 2020/9/4.
// Copyright © 2020 gramm. All rights reserved.
//
import Foundation
public extension Float {
/// 保留小数点后两位输出string
/// - Returns: description
func point2Str() -> String {
let str = String(format: "%.2f", self)
return str
}
/// 根据大小返回磁盘大小描述
/// - Returns: description
func memorySizeString() -> String {
if self < 0 {
return "0KB"
}
if self > 1 {
if self >= 1000 {
let r = self / 1000.0
return "\(r.point2Str())GB"
} else {
return "\(self.point2Str())MB"
}
} else {
return "\((self * 1000).point2Str())KB"
}
}
}