Round data to 2^n values

Hello everyone,

Is there a way to round numbers to 2^n values?
For exampe:

  1. I have the number 0,2 and it should round to 1, since 2^0 is 1.
  2. I have the number 9 and it should return 16, since 2^4 is 16 (2^3 is 8, its closer, but it should always round up)

I hope this was kinda understandable, thank you in advance!

Hello @needknimehelp,

you can use following expression in Math Formula node:

ceil( pow( 2, ceil( ln($yourColumnName$)/ln(2) )))

Basically you compute power of 2 based on your value using base 2 logarithm (which is not available so you need to use change-of-base formula). Inner ceil is because you want to round up and outside ceil is for original values lower than 1.

Alternative way is to use Binner (Dictionary) node prior to which you need to create dictionary table of 2^n boundaries and corresponding labels.

Hope this helps!



This seems to work just like I wanted. Thank you!

1 Like

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