Hi i am extreme newbie, i need help to convert float to int including decimal values. Any help?
Hi numan23 welcome to the forum
Unfortunately that is impossible by definition.
Floats are an integer, followed by a decimal point, followed by the fractional part.
Integers are whole numbers only, with no fractional part.
Hi Numan,
Use the built in function int(). int(x) returns an integer version of x. This works on more than just floats; you can use it on strings or any object type that supports it. There is also a function float(), a function str(), a function list(), a function tuple(), a function bool(), and others.
Example: One thing to note; the value int(x) returns will have the digits after the decimal point truncated, not rounded, so int(1.75) will return 1. You may want to use int(round(x)).
I hope this may help.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.