lib/rents/currency.rb in rents-1.0.5 vs lib/rents/currency.rb in rents-1.0.6
- old
+ new
@@ -4,10 +4,19 @@
# Receive it amount in Decimal and convert to operator str, like 10,00 or 10.00 to 1000
def self.to_operator_str(amount)
# Check invalid entry
return nil if amount.nil?
return amount.to_s if amount.is_a?Integer
- return amount if amount.is_a?(String) && (amount.index('.').nil? || amount.index(',').nil?)
+ amount = format('%.2f', amount) if amount.to_s.float?
+
+ if amount.is_a?String
+ return amount if amount.index('.').nil? && amount.index(',').nil?
+
+ amount = amount.remove('.')
+ amount = amount.remove(',')
+
+ return amount
+ end
# Convert from BigDecimal
if amount.is_a?BigDecimal
aux_amount_str = amount.to_s('F')
cents = aux_amount_str[aux_amount_str.index('.'), aux_amount_str.length]
\ No newline at end of file