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?
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.
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!!
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 :
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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?