KMPageSizeTool.swift 718 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // KMPageSizeTool.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/9/26.
  6. //
  7. import Cocoa
  8. class KMPageSizeTool: NSObject {
  9. class func conversion(withUnit: String, value: CGFloat) -> String {
  10. var f = value
  11. if (withUnit == "cm") {
  12. f = value / 10.0
  13. } else if (withUnit == "in") {
  14. f = value / 25.4
  15. } else {
  16. f = value
  17. }
  18. if (fmod(f, 1) == 0) { //如果有一位小数点
  19. return String(format: "%.0f", f)
  20. } else if (fmod(value * 10, 1) == 0) { //如果有两位小数点
  21. return String(format: "%.1f", f)
  22. } else {
  23. return String(format: "%.2f", f)
  24. }
  25. }
  26. }