Digital ACT-191 ONEAPP-9314 story: remove a decimal for price if decimal is 0
This commit is contained in:
parent
73db6dff2d
commit
20c407f82a
@ -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() } }
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user