diff --git a/VDS/Components/PriceLockup/PriceLockup.swift b/VDS/Components/PriceLockup/PriceLockup.swift index 6cda4cf4..4d21b42c 100644 --- a/VDS/Components/PriceLockup/PriceLockup.swift +++ b/VDS/Components/PriceLockup/PriceLockup.swift @@ -86,7 +86,7 @@ open class PriceLockup: View { open var leadingText: String? { didSet { setNeedsUpdate() } } /// Value rendered for the component. - open var price: CGFloat? { didSet { setNeedsUpdate() } } + open var price: Float? { didSet { setNeedsUpdate() } } /// Color to the component. The default kind is primary. open var kind: Kind = .primary { didSet { setNeedsUpdate() } } @@ -197,7 +197,7 @@ open class PriceLockup: View { } } } - + //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -303,7 +303,7 @@ open class PriceLockup: View { } if let value = price { strikethroughLocation = index - let valueStr = "\(value)" + let valueStr = "\(value.clean)" text = text + currency + valueStr index = index + valueStr.count + 1 strikethroughlength = valueStr.count + 1 @@ -320,3 +320,10 @@ open class PriceLockup: View { } } + +extension Float { + // remove a decimal from a float if the decimal is equal to 0 + var clean: String { + return self.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self) + } +}