How to cut off the end by converting double to int?

Double myDouble = 4.5234234; int result = (int)myDouble; //at this point result is 4 This will "strip" everything after the decimal point, and only return the whole number part of the double.

1 if you do it this way you probably need to ensure that myDouble is in range for int first – jk. Mar 3 at 13:22 @jk - That is true. You might get some unexpected results if not.

One way is to check if myDouble > int. MaxValue or not. – Øyvind Knobloch-Bråthen Mar 3 at 13:31.

You can use Math. Truncate method. Return Value Type: System.

Double The integral part of d; that is, the number that remains after any fractional digits have been discarded.

A nasty but workable way is I guess to round it first using double d = 5.555; int a = (int)d.

Why Math. Floor before the cast? The cast to int will effectively "floor" the value for you anyway, so the Math.

Floor call is redundant. – Øyvind Knobloch-Bråthen Mar 3 at 9:41 Ah you are right, I had forgot about that :) – Anders Mar 3 at 9:44 1 -5.55 will return -6, not -5 with this solution. – Fredrik Mörk Mar 3 at 9:44.

You can use Convet method: double d = 5.555; int I = Convert. ToInt(d); Mitja.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions