> For the complete documentation index, see [llms.txt](https://hopemoore.gitbook.io/coding-for-creatives-spring-2021/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hopemoore.gitbook.io/coding-for-creatives-spring-2021/glossary-and-terms/variables/data-types/floating-point-or-float.md).

# Floating Point or Float

## Description

* Number with a decimal point
* Used for precision
* Used for percentages, but between 0 and 1 (0 and 100%)
* Used for time

**Examples:**

*Processing:*

```java
float speed = 2.5;
```

*JavaScript:*

```javascript
var percentage = 0.25;
```

*Python:*

```python
percentage = 0.25
```

{% hint style="info" %}
Some languages have multiple types with decimal points

Example: a float in C# or Unity will need an `F` after the number in the code to tell it is a float and not something els&#x65;**.** See the example below.
{% endhint %}

```csharp
float speed = 2.5F;
```

^ This is one of the more common errors - forgetting that F.

{% hint style="warning" %}
Do not use commas in your numbers!
{% endhint %}

## Shortcuts (Assignment Operators)

### Quick Math

**`+=`** means “add this”

**`-=`** means “subtract this”

**`*=`** means “multiply it by this”

**`/=`** means “divide it by this”

{% hint style="warning" %}
This updates the variable when used.
{% endhint %}

**Example:**   &#x20;

*Processing, Java-based, and C-based:*

```java
float opacity = 0.5;

println(opacity);        // Prints "0.5"

opacity += 0.15;

println(opacity);        // Prints "0.65"
```

*Python:*

```python
opacity = 0.5

print(opacity)        # Prints "0.5"

opacity += 0.15

print(opacity)        # Prints "0.65"
```
