Round a number value to a multiple

Hello Knimers! How you doing?,

Well, maybe someone can help me with this Issue. I’m trying to round to a multiply some numbers, trying to do something like the MROUND function in excel, for example:

Round to Multiply 7:

*Round Up 16 = 21
*Round Down 16 = 14

It is possible to do this in Knime? I tried the Math Formula and Double Round nodes but I don’t find a function that helps me to do what i’m trying.

Thanks!

Greetings Knimers!

Hi Andres, I found in R a package called DescTools that has a function called MROUND, but I was not able to
execute it see the image.

However there is an option to create your own R function as I found in two websites.

Please find the attached workflow, but check the calculations.

Hope it helps

MROUND.knwf (12.1 KB)

1 Like

I think just a Java Snippet or the Math node should get you to a result. Check it out.

kn_example_mround_java.knwf (14.5 KB)

2 Likes

Hi Andreas!

I’m doing fine despite Croatia losing in World Cup Finals yesterday :slight_smile:

What I would do is write MROUND functions using Math Formula node.

*Round up
$column1$+7-mod($column1$, 7)

*Round down
$column1$-mod($column1$, 7)

Additionally you can add floor or ceil functions if using float numbers and some IFs for special cases if there are some of course.

Br,
Ivan

3 Likes

Thank you everyone,

I tried the three suggestions and worked really great.

Thanks Knimers for your help.

Greetings :smiley:!

3 Likes