+ 1

Can u perform type conversion integer to float?

This is an example of above problem a=4 c=float(a) print(c)

27th Jun 2019, 9:58 AM
Anikesh Kumar
Anikesh Kumar - avatar
13 Respostas
+ 3
In both case int to float or vice versa we can perform no matter size of data type in python
27th Jun 2019, 10:29 AM
Anikesh Kumar
Anikesh Kumar - avatar
+ 3
No, we can not declare 6.23 as integer but we can change in integer like a=6.23 b=int(a) print(a)
27th Jun 2019, 10:38 AM
Anikesh Kumar
Anikesh Kumar - avatar
+ 3
I assume you are talking about Python. Yes, you can always convert floats to integers and integers to floats.
27th Jun 2019, 10:39 AM
Seb TheS
Seb TheS - avatar
+ 3
All can see executable code of this problem after the open my profile and open code
27th Jun 2019, 10:43 AM
Anikesh Kumar
Anikesh Kumar - avatar
+ 3
yes anikesh kumar you are right it has converted float data type to integer đŸ‘đŸ»đŸ‘đŸ»
27th Jun 2019, 10:45 AM
Anubhav Sharma
Anubhav Sharma - avatar
+ 2
we can use integers in float it is accepted as obviously 6 is 6.00 and is acceptable float with no numbers after decimal point however vice versa cannot be done i.e we cannot write say 6.23 as an integer
27th Jun 2019, 10:32 AM
Anubhav Sharma
Anubhav Sharma - avatar
+ 2
Yes we can it reduce the 6.23 into 6. You can write code and check it
27th Jun 2019, 10:34 AM
Anikesh Kumar
Anikesh Kumar - avatar
+ 1
yes that is right float stores 4 bytes whereas int can 2 bytes (in general say c++)
27th Jun 2019, 10:10 AM
Anubhav Sharma
Anubhav Sharma - avatar
+ 1
Yes u all are right thanks
27th Jun 2019, 10:16 AM
Anikesh Kumar
Anikesh Kumar - avatar
+ 1
no anikesh kumar you cannot declare 6.23 as an integer obviously if u round it to 6 then yes 6 can be declared as integer
27th Jun 2019, 10:35 AM
Anubhav Sharma
Anubhav Sharma - avatar
0
Yes, you can.
27th Jun 2019, 10:06 AM
Airree
Airree - avatar
0
How?
27th Jun 2019, 10:07 AM
Anikesh Kumar
Anikesh Kumar - avatar
0
Like in the code above.
27th Jun 2019, 10:07 AM
Airree
Airree - avatar