Closed shah-smit closed 4 years ago
ruby likes to print floats in exponential form. You can tell it not to using sprintf formatting strings such as %5.1f
For example: sprintf('%5.1f',transaction['amount'])
-- Badger
amount = "1234.50000"
def filtered_amount(amount)
decimal_amt = amount.split('.', -1)[1]
after_index = -1
for i in 0..decimal_amt.length - 1
current_char = decimal_amt[i]
if current_char == '0' && after_index == -1
after_index = i
elsif current_char != '0'
after_index = -1
end
end
first_part = decimal_amt[0..after_index]
return amount.split('.', -1)[0] << "." << first_part
end
puts "Before: " << amount
puts "After: " << filtered_amount(amount)
This would help with removing the padding zeros
I have Kafak <> Logstash (then Ruby) <> Elastic
Kafak Input:
Logstash:
Ruby
This prints:
Why I am not getting 100.5?