How to get numbers after decimal point?


Question

How do I get the numbers after a decimal point?

For example, if I have 5.55, how do i get .55?

1
89
4/16/2018 3:02:18 PM

Accepted Answer

An easy approach for you:

number_dec = str(number-int(number))[1:]
23
3/5/2012 5:02:57 AM

5.55 % 1

Keep in mind this won't help you with floating point rounding problems. I.e., you may get:

0.550000000001

Or otherwise a little off the 0.55 you are expecting.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon