Mar-05-2021, 10:29 AM
Hi,
I'm trying to get my head round this: I've rounded all items in a list (List A) to 5 decimal places and created a variable (List B) that takes the rounded numbers from List A and adds a constant. Upon exporting the lists to Excel, I realised that some values in list B have not been rounded to 5 decimal places as you can tell from the second row in the Excel spreadsheet (0.100469999999999). I don't understand why this happens as each item in List A is rounded, when adding 0.01 in List B shouldn't mess up the decimal places, right? Thanks!
A 0.090470000000000
B 0.100469999999999
A 0.092480000000000
B 0.102480000000000
I'm trying to get my head round this: I've rounded all items in a list (List A) to 5 decimal places and created a variable (List B) that takes the rounded numbers from List A and adds a constant. Upon exporting the lists to Excel, I realised that some values in list B have not been rounded to 5 decimal places as you can tell from the second row in the Excel spreadsheet (0.100469999999999). I don't understand why this happens as each item in List A is rounded, when adding 0.01 in List B shouldn't mess up the decimal places, right? Thanks!
List_float = [float(i) for i in String] List A = [round((i/2300), 5) for i in List_float] List B = [i + 0.01 for i in List A]When displaying 15 decimal places in Excel:
A 0.090470000000000
B 0.100469999999999
A 0.092480000000000
B 0.102480000000000