Extract Decimal Numbers in Python: 2 Easy Methods
To extract the numbers after the decimal point, you can achieve this by using string slicing or mathematical operations.
Option 1: Method 1 involves utilizing string slicing operations.
num = 3.14159
decimal_part = str(num).split('.')[1]
print(decimal_part) # 输出:14159
Option 2: Utilize mathematical operations.
num = 3.14159
decimal_part = num - int(num)
print(decimal_part) # 输出:0.14159
Both of these methods can help you retrieve numbers after the decimal point. The choice of method depends on your specific needs.