python convert percentage value into decimal number
Python[Edit]
+
0
-
0
python convert percentage value into decimal number
1 2 3 4 5 6 7 8 9 10def percent_to_decimal(percent): return float(percent[:-1]) / 100.0 # Usage example: print(percent_to_decimal('10%')) # 0.1 print(percent_to_decimal('20%')) # 0.2 print(percent_to_decimal('50%')) # 0.5 print(percent_to_decimal('100%')) # 1.0
[Edit]
+
0
-
0
python convert percentage value into decimal number
1 2 3 4value = '50%' result = float(value[:-1]) / 100.0 print(result) # 0.5