can any one explain me diff. b/w (int32)ft, Convert.ToInt32(ft);
float ft=123.45f;
int nm = (Int32)ft;
int nm2=Convert.ToInt32(ft);
int nm = (Int32)ft;
int nm2=Convert.ToInt32(ft);
Both give same output
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 5, 2015, 10:09 AM EST
A cast always rounds towards zero.
However, Convert.ToInt32 rounds to the nearer integer. If the float is halfway between two integers, the even integer is returned. So 123.5f would round to 124 rather than 123.
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 5, 2015, 4:01 PM EST