# Why does calculation within FVector2D declaration not work?

**URL:** <https://forums.unrealengine.com/t/why-does-calculation-within-fvector2d-declaration-not-work/492848>\
**Category:** C++\
**Tags:** fvector, unreal-engine, UE5-0, question, UE4-27\
**Created:** [January 31, 2022, 10:54pm UTC](https://forums.unrealengine.com/t/why-does-calculation-within-fvector2d-declaration-not-work/492848 "2022-01-31T22:54:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KnitterX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KnitterX](https://forums.unrealengine.com/u/KnitterX)\
**Post date:** [January 31, 2022, 10:54pm UTC](https://forums.unrealengine.com/t/why-does-calculation-within-fvector2d-declaration-not-work/492848/1 "2022-01-31T22:54:03Z")

</div>

It took my way too long to figure out where my code is not doing what it should be doing.  
I don’t understand why this doesn’t work. Especially, because I saw more or less the same code in a tutorial.  
So here is an example:

```auto
const FVector2D CurrentLocation1 = FVector2D((4 + 1) / 10, (4 + 1) / 10);
UE_LOG(LogTemp, Warning, TEXT("CurrentLocation1: %s"), *CurrentLocation.ToString());
const FVector2D CurrentLocation2 = FVector2D(0.5, 0.5);
UE_LOG(LogTemp, Warning, TEXT("CurrentLocation2: %s"), *CurrentLocation.ToString());

```

The log says

> CurrentLocation1: X=0.000 Y=0.000  
> CurrentLocation2: X=0.500 Y=0.500

Why is that? Am I missing something here? Why can’t I do basic calculations in the declaration of the FVector2D while in the sample project I got this from they are doing all kinds of calculations in that line?

Edit: It seems like the problem lies in the division because (4+1) logs as 5 while (4+1)/10 logs as 0. But I still don’t understand why divisions shouldn’t be possible.

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [February 1, 2022, 9:22am UTC](https://forums.unrealengine.com/t/why-does-calculation-within-fvector2d-declaration-not-work/492848/2 "2022-02-01T09:22:01Z")

</div>

Because you’re using integers in the first example rather than floats. The difference is _very_ important since integer division does not produce floating-point values.

In this case the integer operations will be performed first. They will then be implicitly casted to floats when initializing the FVector2D.

---

<div class="post-metadata">

**Author:** ![KnitterX](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KnitterX](https://forums.unrealengine.com/u/KnitterX)\
**Post date:** [February 1, 2022, 10:19am UTC](https://forums.unrealengine.com/t/why-does-calculation-within-fvector2d-declaration-not-work/492848/3 "2022-02-01T10:19:38Z")

</div>

You’re right. Thank you!  
Someone on the subreddit already pointed that out to me. I haven’t had the chance to test yet, but it’s pretty safe to say that that’s the problem.  
I kind of assumed that (4+1)/10 would automatically result in a float. I guess I’m spoiled by blueprint.
