c - How to concatenate two integer variables and make a float variable? -
i have 2 integer variables , result has stored in float. wanted concatenate 2 integer variables , store them floating value. let me know method of joing 2 integer values.
example. have below function call. storing value received key variable lat_int , lat_float. wanted combine both , store in latitude , globally declared float value.
void setcustomcoordinate(int cord_para[]) { lat_int=cord_para[0]; lat_float=cord_para[1]; long_int=cord_para[2]; long_float=cord_para[3]; latitude=(lat_int+lat_float)/100); longitude=(long_int+long_float)/100)); }
this not code question, more basic arithmetics question:
how transform 2 values
a
,b
givea.b
?
simply using addition , multiplication:
int a=10; int b=20; float r=0; r = a+(b/100f);
thre's no need operator (it takes 2 cpu instructions calculate value, calling function more expensive) ; , it's not called "concatenation", addition , multiplication (again).
if want concatenation, should instead have "10" , "20" strings concatenate using dot, example, string concatenation:
printf("%s.%s", "10", "20");
Comments
Post a Comment