424,984 Members | 1,461 Online
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

# Convert Floating Point numbers to integer

 P: 16 Hi... Can anyone help me with the code to convert 4E+07 to 40,000,000 in c# Thanks, Bh... Jan 6 '09 #1
7 Replies

 Expert 5K+ P: 7,872 If the number is already in a float or double datatype, just type cast it down to an int. EDIT: After seeing the example below, I suppose I should provide one too Expand|Select|Wrap|Line Numbers   //Need to append F to store it in a float percision float myfloat = 4E+07F; //or you could store it as a double double mydouble=4E+07;   int myint=(int)myfloat; //or int myint=(int)mydouble;     Jan 6 '09 #2

 100+ P: 344 Hello Bhavs, Type Casting like Plater said, float x = 12.8; int n = (int) x; or int n = ConvertToInt32(x); Jan 6 '09 #3

 P: 18 HI ,Bassem why you use 12.8? represent what? Jan 7 '09 #4

 100+ P: 344 Hello uogen It represents nothing except a floating point number, any number i meant. So, you can convert a float number to integer by truncate the fraction. Regards, Bassem Jan 7 '09 #5

 10K+ P: 13,264 Of course the solutions given are correct only if the floating point number is less than the largest int. Jan 7 '09 #6

 100+ P: 344 Sure, r035198x. Otherwise we may use long int64. Jan 7 '09 #7

 10K+ P: 13,264 @Bassem Which also has a maximum value ... Jan 8 '09 #8