SA-MP Forums Divide operator doesnt work properly?
 New Account Members List Search Today's Posts Mark Forums Read

 30/07/2011, 01:35 PM #1 pen_theGun Big Clucker     Join Date: Jan 2008 Posts: 179 Reputation: 0 Divide operator doesnt work properly? Do i something wrong or does divide operator work incorrect?! Here are some examples pawn Code: `printf( "%f", 5.0/8 ); // OK => 0.625000printf( "%f", 5/8.0 );  // OK => 0.625000printf( "%f", 5/8 ); // Wrong? => 0.000000printf( "%d", 5/8 ); // Wrong? => 0printf( "%d", 10/5 ); // OK => 2printf( "%f", 10/5 ); // Wrong? => 0.000000printf( "%f", float(10/5) ); // OK => 2.000000` Isnt job of print to provide me an correct output, instead of making float(10/5) etc.? __________________
 30/07/2011, 01:50 PM #2 jamesbond007 Gangsta     Join Date: Oct 2009 Location: Canadia Posts: 788 Reputation: 50 Re: Divide operator doesnt work properly? looks right u cant use whole numbers when using float use instead : pawn Code: `printf("%f", 10/5.0);`
 30/07/2011, 02:58 PM #3 cessil High-roller     Join Date: Apr 2009 Posts: 1,352 Reputation: 296 Re: Divide operator doesnt work properly? use floatdiv(float1,float2) __________________ [UPDATED 02/9/2013]AntiCheat Tips 'n' Tricks Click Me!
 30/07/2011, 04:06 PM #4 Double-O-Seven Guest   Posts: n/a Re: Divide operator doesnt work properly? I can tell you what's wrong: Nothing. pawn Code: `printf( "%f", 5.0/8 ); // OK => 0.625000printf( "%f", 5/8.0 );  // OK => 0.625000printf( "%f", 5/8 ); // Wrong? => 0.00000  NOT WRONG! 5 / 8 == 0 is an integer division. (See below)printf( "%d", 5/8 ); // Wrong? => 0 NOT WRONG! That's an integer divison. 5 / 8 is not an integer and smaller than 1.printf( "%d", 10/5 ); // OK => 2printf( "%f", 10/5 ); // Wrong? => 0.000000 NOT WRONG! 10 / 5 == 2 is an integer division.// It's binary form is 0b0000...010 (30 zeros, 1 one and 1 zero.). However, 0b000...010 as integer is not the same number as floating point number which is in this case probably a number very close to 0. printf( "%f", float(10/5) ); // OK => 2.000000` The only problem here is that you did not understand what exactly happens.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Gemini Help Archive 3 11/02/2011 03:07 PM Scenario Help Archive 24 11/12/2010 10:54 PM aNdReSkKkK Help Archive 0 08/02/2010 04:40 AM [GM]The_Don Help Archive 4 07/02/2010 01:17 PM

All times are GMT. The time now is 10:02 AM.

 -- (EN) English -- (RU) Русски SA-MP - Archive - Top