# Type conversion from string float value to int is failing

**URL:** <https://discuss.python.org/t/type-conversion-from-string-float-value-to-int-is-failing/57627>\
**Category:** Python Help\
**Created:** [July 8, 2024, 2:24pm UTC](https://discuss.python.org/t/type-conversion-from-string-float-value-to-int-is-failing/57627 "2024-07-08T14:24:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunilgv62](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@sunilgv62](https://discuss.python.org/u/sunilgv62)\
**Post date:** [July 8, 2024, 2:24pm UTC](https://discuss.python.org/t/type-conversion-from-string-float-value-to-int-is-failing/57627/1 "2024-07-08T14:24:14Z")

</div>

I am trying the below code but it is failing.

Var = int(‘3.3’)  
Print(var)

Result:  
Error is the result.

But i tried the following code

Var = int(‘3’)  
Print(var)  
Result:  
3

I am using the following version.  
Version: 2.7.7

---

<div class="post-metadata">

**Author:** ![jamestwebber](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jamestwebber/32/12799_2.png) [@jamestwebber](https://discuss.python.org/u/jamestwebber)\
**Post date:** [July 8, 2024, 2:32pm UTC](https://discuss.python.org/t/type-conversion-from-string-float-value-to-int-is-failing/57627/2 "2024-07-08T14:32:09Z")

</div>

`'3.3'` can not be translated into an integer, so `int` is failing. If you want to convert it into a `float` you can use `float('3.3')`. If you want to convert the _`float`_ into an `int` you can use ~~`float(int('3.3'))`~~ to get `3`. **edit:** as Cornelius points out, that was backwards, it’s `int(float('3.3'))`

(I’ll also note that you use `Var` for your assignment and try to print `var`, but maybe that was autocorrect)

> [@sunilgv62](#):
>
> I am using the following version.  
> Version: 2.7.7

This version of python has been unsupported since 2020, so I would definitely recommend updating to python 3. There is a small learning curve but since you are currently learning it shouldn’t be a problem, and this way you don’t learn anything that’s woefully obsolete.

---

<div class="post-metadata">

**Author:** ![MegaIng](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/megaing/32/16162_2.png) [@MegaIng](https://discuss.python.org/u/MegaIng)\
**Post date:** [July 8, 2024, 2:50pm UTC](https://discuss.python.org/t/type-conversion-from-string-float-value-to-int-is-failing/57627/3 "2024-07-08T14:50:23Z")

</div>

> [@jamestwebber](#):
>
> If you want to convert the _`float`_ into an `int` you can use `float(int('3.3'))` to get `3`.

Typo, correct is `int(float('3.3'))`, the inner function get’s evaluated first.
