Digital ACT-191 ONEAPP-9314 story: remove a decimal for price if decimal is 0

This commit is contained in:
Vasavi Kanamarlapudi 2024-08-14 15:27:47 +05:30
parent 73db6dff2d
commit 20c407f82a

View File

@ -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)
}
}