+ 2

# How to convert datatypes

WAP to convert int to float.

17th Mar 2020, 11:57 AM
Anonymous World
+ 6
We can use type casting float a; int c; scanf(%d,&a); c=(int)a;
18th Mar 2020, 9:29 AM
+ 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.
17th Mar 2020, 10:17 PM
Silman
+ 3
~ swim ~ Yeah I know, I'm asking bacause you refered to it as casting
17th Mar 2020, 6:11 PM
xaralampis_
+ 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)
17th Mar 2020, 6:15 PM
xaralampis_
+ 3
Yeah I have, that's how I heard it the first time from TheChernoProject on youtube
17th Mar 2020, 6:19 PM
xaralampis_
+ 3
~ swim ~ and yeah you right, they are the same
17th Mar 2020, 6:22 PM
xaralampis_
+ 3
Use type casting
18th Mar 2020, 1:15 PM
AS Raghuvanshi
18th Mar 2020, 1:40 PM
18th Mar 2020, 1:44 PM
+ 2
by use of type casting
18th Mar 2020, 5:29 PM
Mitraj Gohil
+ 2
a = 5 b = (int)a
19th Mar 2020, 7:14 AM
Rajarshi Roy
+ 2
In java The answer would be int a=5; float b=(int)a
19th Mar 2020, 8:37 AM
Shrinjoy Das
+ 1
~ swim ~ isn't that called explicit conversion?
17th Mar 2020, 6:07 PM
xaralampis_
+ 1
In java simply declare a float and move your int into it: int a = 0; float f = (float) a;
18th Mar 2020, 11:26 AM
Kavoos Salahi
+ 1
18th Mar 2020, 1:47 PM