Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to print specific number right of the decimal point

1.45
4

Hey everyone i need to print number right of the decimal point like if i input 1.45 it needs to output 4 because its first number after point i also tried multiplying by 10 or 100 but i dont know much numbers will be after point so if there is 3 numbers after point youn still need to print the first number after point. I have tried using ".2f" which didnt work it just made things worse i also tried finding things in internet all i found was about ".2f".

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could just multiply by 10, ignore any fractional component by converting to int then print the value modulus 10. Like this:

n = 1.45

print(int(n * 10) % 10)

Output:

4
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading