Skip to content
Advertisement

How to round certain values in list

I have a list in Python

JavaScript

I want to round first three values

JavaScript

I need to round down to 100.0 if they are < 130.0 and then similarly round down to 200 if they are < 230 and so on.

Advertisement

Answer

Based on comments it seems you want to round down to 100.0 if they are < 130.0 and then similarly round down to 200 if they are < 230 and so on.

So the following:

JavaScript

So for every element x of list a, if the remainder of dividing it by 100 is less than 30 we have to round it down other wise keep x.

For rounding down to 100, 200, … integer divide x by 100 and then multiply again by 100.

Example

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement