# Divide a field by a number in ruby

**URL:** https://discuss.elastic.co/t/divide-a-field-by-a-number-in-ruby/226306
**Category:** Logstash
**Created:** [April 3, 2020, 2:24am UTC](https://discuss.elastic.co/t/divide-a-field-by-a-number-in-ruby/226306 "2020-04-03T02:24:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lfuentes](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@lfuentes](https://discuss.elastic.co/u/lfuentes)
#### Post date: [April 3, 2020, 2:24am UTC](https://discuss.elastic.co/t/divide-a-field-by-a-number-in-ruby/226306/1 "2020-04-03T02:24:05Z")

</div>

Good, I need help please, I need to divide a number by 1000 using the ruby filter, could you help me with the code of that? I am really a beginner, I have something like this:

ruby {  
code =\> "event.set('timetaken', event.get('valor') / event.get('1000'))"  
}

I know that is wrong, since it gives me "Ruby exception occurred: undefined method` / 'for "187": String "error, the truth is that I could not find the syntax, please help

Thank you so much

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [April 3, 2020, 1:45pm UTC](https://discuss.elastic.co/t/divide-a-field-by-a-number-in-ruby/226306/2 "2020-04-03T13:45:25Z")

</div>

> [@lfuentes](#):
>
> code =\> "event.set('timetaken', event.get('valor') / event.get('1000'))"

The error message indicates [valor] is a string, so you need to convert it to a number. You could try

```
code => "event.set('timetaken', event.get('valor').to_f / 1000)"

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 1, 2020, 1:45pm UTC](https://discuss.elastic.co/t/divide-a-field-by-a-number-in-ruby/226306/3 "2020-05-01T13:45:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
