c++ cli - Casting from double to int - Warning in Visual C++/CLI -


i have property that's double in c++/cli need cast integer, compiler gives me warning (c4244) when so. example:

//"value" double int newvalue = (int)(control->value); //c4244 

i understand compiler isn't happy because double might larger int can hold, particular control guaranteed value 1 10, i know okay. can eliminate warning somehow?

the compiler warning not might out of range, might lose information (it needs round number somehow, , afraid own).

use floor() tell know you're doing:

int newvalue = floor(control->value);  

or cast explicitly tell compiler there's nothing implicit going on, , know you're doing:

int newvalue = (int)(float)(control->value);  

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -