I have a list that includes float prices, but they are detailed to proceed I know that we (" % .f "% variable) can be reduced to an operator like:
result = [359.70000000000005] result ="% .2f "% result result = [35 9 .70] My question is how can we change the list of prices without using a recurrent.
list = [0.30000000000000004, 0.5, 0.20000000000000001] list = "% 2f"% list typeError: all logos that were not changed during string formatting How can I provide a clean list:
list = [0.30, 0.5, 0.20] This can be a silly question because I'm new Starting Python Sorry for this ..
"% .2f" does not return Clear Float gives a string representing this float with two decimals. myList = [0.30000000000000004, 0.5, 0.20000000000000001] myFormattedList = ['% .2f'% MyList] Returns:
Other than this, do not call your variable list ; ['0.30', '0.50', '0.20'] This is a reserved word for listing, for example myList . If you want to get the [0.30, 0.5, 0.20] (or at least that float which is the closest possible), you can try it: [0.29999999999999999, 0.5, 0.20000000000000001]
Comments
Post a Comment