# Rounding numbers in python

#1

Hi All,

Following the next thread:

I want to round number by 50 places ie. if I have 150 >>>150, 136 >>>> 150, 151 >>>> 200, and so on…

Can I do it with round() built-in function or I have to make a custom function?

Any help will be appreciated.

Thanks!

0 Likes

#2

Not familiar with the Python methods but it should be doable. You can also use DesignScript methods in Python if you load DSCore Nodes.

1 Like

#3

like this

`Math.Round(num/50)*50`

1 Like

#4

@Nick_Boyts thanks for the answer, and how would you do it with DesignScript methods?

0 Likes

#5

Thanks a lot!!

1 Like

#6

Nice solution @erfajo. Only I want to always round “up”, ie. 516 >>>>> 550, 510>>>>>550.

0 Likes

#7

Then do this

`Math.Ceiling(num/50)*50`

0 Likes

#8

Sorry I thought you were specifically looking for Python solutions.

Round node is from Clockwork.

2 Likes

#9

@Nick_Boyts
It is the same code whether it is DesignScript, Python, or any other coding language

0 Likes

#10

Thanks. I’ll check what’s the algorith in that node. Actually, I was looking for the algorithm. Thanks both @erfajo and @Nick_Boyts

1 Like

#11

here you have in python…

``````import math
numbers = IN[0]

result = []
for num in numbers:
result.append(math.ceil(num/50)*50)

OUT = result
``````

2 Likes

Python Nodes Basics