I want to add a `float`

by 2% but can’t. Already tried `float += 2/100`

but it won’t add up.

Any ideas?

I want to add a `float`

by 2% but can’t. Already tried `float += 2/100`

but it won’t add up.

Any ideas?

how about

`value *= 1.02f`

That will increase the value by 2% of its current value (to a total 102% or 1.02)

If you want to add 2/100, like you wrote

`value += 2/100`

then you should know that `2/100`

is an integer division and will evaluate to `0`

. Make at least one of those operands float by casting `(float)2/100`

or using float literals `2f/100f`

I’m not quite sure what exactly your goal is. If you want to “add” 2% of the current value to the value, you have to do either

```
v += v * 2f / 100f;
```

or

```
v += v * 0.02f;
```

or

```
v *= 1.02f;
```

Which all do the same thing. Which means if “v” has a value of `100`

, the result will be `102`

. Though of course when you do it again, you will end up with `104.04`

which is 102% of 102.

That’s all just basic algebra.