From 20c407f82af725d7dae03a224af8959bc55bcefe Mon Sep 17 00:00:00 2001 From: Vasavi Kanamarlapudi Date: Wed, 14 Aug 2024 15:27:47 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-9314 story: remove a decimal for price if decimal is 0 --- VDS/Components/PriceLockup/PriceLockup.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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) + } +}