fedorqui Asked: 2020-02-14 05:40:48 +0800 CST 2020-02-14 05:40:48 +0800 CST 2020-02-14 05:40:48 +0800 CST How to convert a String type to Float or Int? 772 In Python, how can I convert a string "123.456"to a decimal number 123.456? And how a string "32"to an integer 32? python 1 Answers Voted Best Answer fedorqui 2020-02-14T05:40:48+08:002020-02-14T05:40:48+08:00 Use float()to convert to decimal and int()to convert to integer: >>> a="123.456" >>> float(a) 123.456 >>> int(float(a)) 123 >>> b="32" >>> int(b) 32
Use
float()
to convert to decimal andint()
to convert to integer: