By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,404 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,404 IT Pros & Developers. It's quick & easy.

Floating Point to Integer?

P: 21
Hi all first time posting in a while sry if i mess something up. Anyway I am using 2d arrays to make a game with pygame and i alter coordinates on this array by smaller than 1 increments. Then i need to reference the coordinates in an If statement. However by this time in the program the coordinates have been altered to non integer numbers. My question is how can i turn these floating point numbers into whole integers.

code = [python]

PS: I have already tried the round function. This does give integers but it adds a .0 to the end so like the floating point number 89.9 turns into 90.0 and i cant use it seeing as how it has a decimal place after the integer.

thanx in advance
Feb 16 '09 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 469
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.
I hope this helps.
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)).
Feb 16 '09 #2

P: 21
cool thanx alot man works nicely
Feb 17 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.