27 lines
709 B
Swift
27 lines
709 B
Swift
//
|
|
// MoneyFormatter.swift
|
|
// SHECommunity
|
|
//
|
|
// Created by Lin on 2024/12/24.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class MoneyFormatter: NSObject {
|
|
|
|
static let shared = MoneyFormatter()
|
|
|
|
func verifyFormat(money: String) -> String {
|
|
var tempValue = money
|
|
// 处理是否保留小数点后面的数值
|
|
var lastStr = ""
|
|
// 处理支持小数点的金额
|
|
if let dotIndex = tempValue.firstIndex(of: ".") {
|
|
lastStr = String(tempValue.suffix(from: dotIndex)).replacingOccurrences(of: ".", with: "")
|
|
lastStr = "." + lastStr.prefix(2)
|
|
tempValue = String(tempValue.prefix(upTo: dotIndex))
|
|
}
|
|
return tempValue + lastStr
|
|
}
|
|
}
|