mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-22 22:59:39 +02:00
12 lines
264 B
Ruby
12 lines
264 B
Ruby
|
class Numeric
|
||
|
def cents(precision: 2)
|
||
|
return "" unless precision.positive?
|
||
|
|
||
|
cents = self.to_s.split(".")[1]
|
||
|
cents = "" unless cents.to_i.positive?
|
||
|
|
||
|
zero_padded_cents = cents.ljust(precision, "0")
|
||
|
zero_padded_cents[0..precision - 1]
|
||
|
end
|
||
|
end
|