
Calvin D. answered 10/21/21
Data Scientist
Let's say we have a list of values, in decimal form.
If we want them to be in normal percent form, there are a few things we can do. We can just multiply every value by 100, turning it into a decimal:
If we wanted to add a percent sign, we can do that too by modifying the above code slightly:
Maybe we want them not to have a 0 at the end. This happens because the value is a decimal (or a float) and then converted into a string. We can first convert the float into an int, to get rid of that 0.
If we want to make it specific intervals (like 5) then all we would need to do is round the numbers in advance. So for example if you wanted the percent 0.02 (2%) to round to 5%, you'd want to multiply by 100 and then round to the nearest multiple of 5. Here's a program that does it to 10: