How to convert datatypes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to convert datatypes

WAP to convert int to float.

17th Mar 2020, 11:57 AM
Anonymous World
Anonymous World - avatar
16 Answers
+ 6
We can use type casting float a; int c; scanf(%d,&a); c=(int)a;
18th Mar 2020, 9:29 AM
Addaganti Naga Sai Rajeev
Addaganti Naga Sai Rajeev - avatar
+ 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_
xaralampis_ - avatar
+ 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_
xaralampis_ - avatar
+ 3
Yeah I have, that's how I heard it the first time from TheChernoProject on youtube
17th Mar 2020, 6:19 PM
xaralampis_
xaralampis_ - avatar
+ 3
~ swim ~ and yeah you right, they are the same
17th Mar 2020, 6:22 PM
xaralampis_
xaralampis_ - avatar
+ 3
Use type casting
18th Mar 2020, 1:15 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
18th Mar 2020, 1:40 PM
narayanaprasad
narayanaprasad - avatar
18th Mar 2020, 1:44 PM
narayanaprasad
narayanaprasad - avatar
+ 2
by use of type casting
18th Mar 2020, 5:29 PM
Mitraj Gohil
Mitraj Gohil - avatar
+ 2
a = 5 b = (int)a
19th Mar 2020, 7:14 AM
Rajarshi Roy
Rajarshi Roy - avatar
+ 2
In java The answer would be int a=5; float b=(int)a
19th Mar 2020, 8:37 AM
Shrinjoy Das
Shrinjoy Das - avatar
+ 1
~ swim ~ isn't that called explicit conversion?
17th Mar 2020, 6:07 PM
xaralampis_
xaralampis_ - avatar
+ 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
Kavoos Salahi - avatar
+ 1
18th Mar 2020, 1:47 PM
narayanaprasad
narayanaprasad - avatar
+ 1
int a= (int) value; System.out.println(a);
19th Mar 2020, 8:20 AM
samrat kundu
samrat kundu - avatar