hi everyone,
i want to convert a floating number to integer number without make any approximation ex:-
double x = 2.6;
int y = Convert.ToInt16(x) ; // output y= 3
all i need that make y= 2
i used this conversion in c++ vs6 the output with me is 2 please help me reach this output
many thanx
Convert float to int without approximate
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted Nov 3, 2009, 12:13 AM EST
if mys solution helps you then Check "Do you like this answer" check Box please :)
double x = 2.999;
int y = Convert.ToInt16(Math.Truncate(x));
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 3, 2009, 12:38 AM EST
Use this.
Mohammed Gamal67 reputationPosted Nov 3, 2009, 1:36 AM EST
Mohammed Gamal67 reputationPosted Nov 3, 2009, 1:37 AM EST