jsdw_ios/QuickLocation/Manager/Money/MoneyFormatter.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
}
}