In python, I import a file that has different length decimal places in the numbers, such as 7.2 or 7.2332 Is it possible to find out the number of decimal places in the number, if so, how? All the question I can find on SO are about formatting to a specific decimal place, but thats not what I am doing.
The application is to use qdoublespinbox and set the decimal places to only the required amount.
Edit:
In context, I am able to print the number, which will print 7.2, or 5.42422 etc. If the command prompt prints the correct digits (ie. doesnt print everything in the memory allocation of a float) is there any way to get that information.
Assuming that 'import a file' means your decimals are string in a file, you can use reverse and find:
>>> f = "7.2332"
>>> f[::-1].find('.')
4
>>> f = "7.20"
>>> f[::-1].find('.')
2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With