Linked Questions
21 questions linked to/from Round to 5 (or other number) in Python
2
votes
3
answers
8k
views
how to find nearest equal or higher multiple of ten in python [duplicate]
I have a this small task , where I am rounding up the number to higher multiple of ten. But want to round it to nearest multiple of ten.
My code :
import math
a = map(int,list(str(7990442)))
b = ...
3
votes
4
answers
1k
views
Is there a way to know whether something was rounded up or down in python? [duplicate]
I basically want to know whether the result of my equation (which is a simple one like this x / y) was rounded up or down.
The reason is that I have two simple statements after the rounding line like ...
1
vote
2
answers
3k
views
How to round off any number to the nearest multiple of 5? [duplicate]
I have been trying to round of any number to the nearest multiple of 5. By saying that, I mean that it should always round up. However, my piece of code is always to rounding off to the nearest ...
1
vote
2
answers
324
views
How to round float in multiple of 5 [duplicate]
I got this number 1.12412 and I want to round it to 1.12415 or 1.12410 (muliple of 5 in last decimal)
If using the Round(X,4) function I get 1.1241 (4 decimals).
Is there a function that can make that ...
0
votes
1
answer
444
views
python round numbers to specific value [duplicate]
I would like to write a specif rounding logic.
number = x
if x < 950:
# round number to and in steps of 50
elif x < 9000:
# round number to and in steps of 100
elif x < 100000:
# ...
0
votes
3
answers
139
views
round down numbers to the next 5 in python [duplicate]
I want to round numbers down to the next 5 in python
What I mean:
1 -> 0
3 -> 0
4 -> 0
5 -> 5
7 -> 5
9 -> 5
...
I already searched a lot for rounding numbers with a base but then ...
0
votes
1
answer
377
views
Round to nearest number between two numbers [duplicate]
How do I round a fraction to the nearest 0.5 between 0.0 and 5.0?
Let's say I've got 11/150, it should convert to 0.0. In addition, 75/150 should convert to 2.5
As for the code I've got this but I'm ...
0
votes
0
answers
57
views
How to round integer value to nearest X multiple in python [duplicate]
Is there a simple way to round in python to the nearest X value? For example, to round to the nearest tens I can do:
>>> round(1845,-1)
1840
What about if I wanted to round to the nearest...?...
0
votes
0
answers
23
views
Python rounding grades [duplicate]
Trying to round student grades to nearest multiple of five. If grade is two or less closer to the round then that grade gets used. What is wrong with my current code
Grade = input(23)
Round_grade = (((...
0
votes
0
answers
15
views
Create a program that can find the nearest hundreds for a given number [duplicate]
I'm using the def function and the for or the while loop to create a program that can find the nearest hundreds for a given number.
41
votes
3
answers
39k
views
Rounding down integers to nearest multiple
Is there a function in Python that allows me to round down to the nearest multiple of an integer?
round_down(19,10)=10
round_down(19,5)=15
round_down(10,10)=10
I conscientiously looked at SO and ...
0
votes
3
answers
13k
views
In Python, how do you display the value of an equation inside of a print function?
Here is my code, in Python:
x=float(raw_input('How many total orders have accumulated: '))
y=float(raw_input('How many units are in the inventory: '))
z=float(raw_input('How many accumulated orders ...
7
votes
7
answers
1k
views
Rounding in Python
Hi everyone I am currently doing a school project and even my teacher is stumped. In Canada the penny has been removed so now all purchases are rounded to either 0 or 5. For example 5.53 would become ...
3
votes
1
answer
2k
views
dynamically connecting Django Q objects with AND and OR
I want users to be able to query my database via several different parameters (name, year, etc), dynamically add more fields, and join them with boolean operators; the net result would be something ...
1
vote
4
answers
358
views
How to round up to the next integer ending with 2 in Python? [closed]
Can you help me to round like the following?
10 -> 12
21 -> 22
22 -> 22
23 -> 32
34 -> 42
I tried answers from below, but all of them are rounding to next multiplier of a number:
Round ...