1234567891011121314151617181920212223242526272829 |
- //
- // KMPageSizeTool.swift
- // PDF Master
- //
- // Created by tangchao on 2023/9/26.
- //
- import Cocoa
- class KMPageSizeTool: NSObject {
- class func conversion(withUnit: String, value: CGFloat) -> String {
- var f = value
- if (withUnit == "cm") {
- f = value / 10.0
- } else if (withUnit == "in") {
- f = value / 25.4
- } else {
- f = value
- }
-
- if (fmod(f, 1) == 0) { //如果有一位小数点
- return String(format: "%.0f", f)
- } else if (fmod(value * 10, 1) == 0) { //如果有两位小数点
- return String(format: "%.1f", f)
- } else {
- return String(format: "%.2f", f)
- }
- }
- }
|