How do I extract the integer without rounding?

 

If I have 159.8 I want 159, not 160.

MathFloor(), MathCeil() and even NormalizeDouble(number, 0) will round the number.

Is there any function that will just drop the fraction and give me the integer without rounding?

 
A way can be convert to string and extract substring before the dot (or comma, it depends on how string will look after conversion)

Probably there are also other ways, but at the moment this is the quickest one that comes into my mind.
 
whoowl:

If I have 159.8 I want 159, not 160.

MathFloor(), MathCeil() and even NormalizeDouble(number, 0) will round the number.

Is there any function that will just drop the fraction and give me the integer without rounding?

Do a cast to integer..

That drops the fractional part.

int value = (int)double_value;
 

Yes, both solutions work. Many thanks.

I had considered converting to string (then to integer later) but thought it was awkward because of the two conversions.

I'm not sure that casting is a better option, but I guess it can't be worse.

 
whoowl #:

Yes, both solutions work. Many thanks.

I had considered converting to string (then to integer later) but thought it was awkward because of the two conversions.

I'm not sure that casting is a better option, but I guess it can't be worse.

Its the only direct conversion there is..- It uses an assember instruction to do it, its implemented in hardware, thats how you do it. - Nothing else can be as direct as this!!

 
whoowl:

If I have 159.8 I want 159, not 160.

MathFloor(), MathCeil() and even NormalizeDouble(number, 0) will round the number.

Is there any function that will just drop the fraction and give me the integer without rounding?

You can try this :

   double value = 159.8;
   int floorvalue = (int)MathFloor(value);
   int ceilvalue = (int)MathCeil(value);
   Print("Floor = ",floorvalue);
   Print("Ceil = ",ceilvalue);

the result is :