+ 2
How to convert datatypes
WAP to convert int to float.
16 ответов
+ 6
We can use type casting
float a;
int c;
scanf(%d,&a);
c=(int)a;
+ 5
xaralampis_ ~ swim ~ explicit conversion is just one way of doing type casting. You could also use implicit conversion. See e.g.
https://www.improgrammer.net/type-casting-c-language/
for more information.
+ 3
~ swim ~ Yeah I know, I'm asking bacause you refered to it as casting
+ 3
~ swim ~ No, I'm not really familiar with casting. I try to understand its difference from the other 2 types of conversions. I mean if you want to do a tradional casting to it you would do:
*((float*)&x)
+ 3
Yeah I have, that's how I heard it the first time from TheChernoProject on youtube
+ 3
~ swim ~ and yeah you right, they are the same
+ 3
Use type casting
+ 2
You may find answer in https://www.tutorialspoint.com/cprogramming/c_type_casting.htm
+ 2
Please see https://www.c-lang.thiyagaraaj.com/archive/c-blog/convert-a-floating-point-value-to-an-integer-in-c also in this regard
+ 2
by use of type casting
+ 2
a = 5
b = (int)a
+ 2
In java
The answer would be
int a=5;
float b=(int)a
+ 1
~ swim ~ isn't that called explicit conversion?
+ 1
In java simply declare a float and move your int into it:
int a = 0;
float f = (float) a;
+ 1
You may try to find answer using Python in https://www.geeksforgeeks.org/type-conversion-python/
+ 1
int a= (int) value;
System.out.println(a);