473,473 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Floating Point to Integer?

21 New Member
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
alex
Feb 16 '09 #1
2 17107
boxfish
469 Recognized Expert Contributor
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.
Edit:
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
PythonNotSoGuru
21 New Member
cool thanx alot man works nicely
Feb 17 '09 #3

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

Similar topics

4
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a...
5
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
2
by: Sheldon Simms | last post by:
I would like to portably extract the components of a floating point value: sign, exponent, and significand. Based on the C floating point model described in 5.2.4.2.2, I came up with the following...
10
by: Shawn | last post by:
Hello all, I apologize as I am sure this has probably been dealth with before... but I am doing an exercise from "Practical C Programming" and I have been unable to get it to work perfectly due to...
6
by: aegis | last post by:
how can I take the fractional part of a floating point value such that I can store that value into an integer type? float foo = 6.180; now take the fractional part such that you can store 180...
7
by: thisismyidentity | last post by:
Hi all, I am trying to predict the behaviour of floating point load and store operations on integer locations. I ve written a small piece of code having some inline assembly code which I am...
39
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
9
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
11
by: Peter | last post by:
I have written this small app to explain an issue I'm having with a larger program. In the following code I'm taking 10 ints from the keyboard. In the call to average() these 10 ints are then...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.