Logstash JSON代码和Ruby无法正确处理小数点浮点数

问题描述

我有Kafak Logstash(然后是Ruby) Elastic

Kafak输入:

{"customerid":"smit","last_name":"shah","age":10,"height":10,"weight":100,"automated_email":false,"header": { "endpoint":"/pay"},"transaction": { "amount":100.50,"currency" : "SGD"}}

Logstash:

 json {
        source => "message"
      }

 mutate {
        convert => { "amount" => "float" }
    }
    ruby {
        # Cancel 90% of events
        path => "/usr/local/etc/logstash/main.rb"
        script_params => { "percentage" => 0.9 }
      }
    }

Ruby

transaction = event.get('transaction')
        puts transaction
        puts transaction['amount']

此打印:

{"amount"=>0.1005e3,"currency"=>"SGD"}
0.1005e3

为什么我没有得到100.5?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)