Rounding

  • Thread starter Zunbeltz Izaola
  • Start date
Z

Zunbeltz Izaola

Hi to all!

I want to know if it is possible to round a floating number to
multiples of another number. An example:
I've spam = 0.36 and foo = 0.38 and i want something like this:
0.50

I know that builtin round rounds to a decimal position, but is there a
module (or it is easy to code) with a function like this?

Thanks in advance

Zunbeltz Izaola
 
Z

Zunbeltz Izaola

def roundto(num,round_multiple):
return round(num/round_multiple)*round_multiple

Pádraig.

Odvious ! I don't know wy my mind is not working properly today!

Zunbeltz
 
P

P

Zunbeltz said:
Hi to all!

I want to know if it is possible to round a floating number to
multiples of another number. An example:
I've spam = 0.36 and foo = 0.38 and i want something like this:



0.50

I know that builtin round rounds to a decimal position, but is there a
module (or it is easy to code) with a function like this?

def roundto(num,round_multiple):
return round(num/round_multiple)*round_multiple

Pádraig.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top