# \[Solved\] How to round floats? (0.234378996=0.23)

**URL:** <https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [May 24, 2020, 4:29am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299 "2020-05-24T04:29:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Apollo1444](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Apollo1444](https://forums.unrealengine.com/u/Apollo1444)\
**Post date:** [May 24, 2020, 4:29am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/1 "2020-05-24T04:29:58Z")

</div>

Hi guys!  
I need to round floats (0.234378996=0.23, 12.3349=12.33, etc.)

I’m trying to use “Snap to grid (0.01)”.  
Sometimes it returns expected results (0.23), but sometimes it returns ugly long numbers (0.234378996)

How to properly round floats?  
(I know this is simple question, but I’ve searched it on forums, didn’t find the answer)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [May 24, 2020, 9:10am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/2 "2020-05-24T09:10:14Z")

</div>

> [@Apollo1444](#):
>
> Hi guys!  
> I need to round floats (0.234378996=0.23, 12.3349=12.33, etc.)
> 
> I’m trying to use “Snap to grid (0.01)”.  
> Sometimes it returns expected results (0.23), but sometimes it returns ugly long numbers (0.234378996)
> 
> How to properly round floats?  
> (I know this is simple question, but I’ve searched it on forums, didn’t find the answer)

![float.JPG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/5/c55dddf7ebffd31fa20cb1e44fb0c4aa09353456.jpeg)

---

<div class="post-metadata">

**Author:** ![Mars007](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mars007](https://forums.unrealengine.com/u/Mars007)\
**Post date:** [May 24, 2020, 9:26am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/3 "2020-05-24T09:26:56Z")

</div>

![float.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/1/e1032509f53a64f95154ec21b8e6fd1d8f4a03a1.png)  
10 chars…

---

<div class="post-metadata">

**Author:** ![Apollo1444](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Apollo1444](https://forums.unrealengine.com/u/Apollo1444)\
**Post date:** [May 30, 2020, 11:30am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/4 "2020-05-30T11:30:30Z")

</div>

> [@Mars007](#):
>
> ![float.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/1/e1032509f53a64f95154ec21b8e6fd1d8f4a03a1.png)  
> 10 chars…

Hi guys! Thx for the answer, but it DOESN’T work at all! It still is returning ugly long floats  
Why is that??

---

<div class="post-metadata">

**Author:** ![Manatee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Manatee](https://forums.unrealengine.com/u/Manatee)\
**Post date:** [May 30, 2020, 1:26pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/5 "2020-05-30T13:26:08Z")

</div>

> [@Apollo1444](#):
>
> Hi guys! Thx for the answer, but it DOESN’T work at all! It still is returning ugly long floats  
> Why is that??

That above does work. Your problem lies somewhere else. This does the rounding only once, so if your float changes via calculations you need to round it again every time.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [May 30, 2020, 2:28pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/6 "2020-05-30T14:28:46Z")

</div>

> [@](#):
>
> ugly long numbers

If this is for display purposes, you can set _Maximum Fractional Digits_ like so:

[https://docs.unrealengine.com/en-US/…oat/index.html](https://docs.unrealengine.com/en-US/BlueprintAPI/Utilities/Text/ToText_float/index.html)

---

<div class="post-metadata">

**Author:** ![Nathaniel3W](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nathaniel3W](https://forums.unrealengine.com/u/Nathaniel3W)\
**Post date:** [May 30, 2020, 3:45pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/7 "2020-05-30T15:45:05Z")

</div>

> [@Apollo1444](#):
>
> Hi guys! Thx for the answer, but it DOESN’T work at all! It still is returning ugly long floats  
> Why is that??

Screenshot your Blueprints and the output of Print String.

---

<div class="post-metadata">

**Author:** ![Apollo1444](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Apollo1444](https://forums.unrealengine.com/u/Apollo1444)\
**Post date:** [June 7, 2020, 2:42am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/8 "2020-06-07T02:42:06Z")

</div>

> [@Nathaniel3W](#):
>
> Screenshot your Blueprints and the output of Print String.

Hi! Here’s my simple blueprint:

> **[Print rounded float posted by anonymous | blueprintUE | PasteBin For Unreal...](https://blueprintue.com/blueprint/0x6wo_3s/)**
>
> No description provided

Can you guys tell me what is wrong? Thanks!

Output (ugly long floats):  
PIE: Play in editor total start time 0,132 seconds.  
LogBlueprintUserMessages: [BP\_Test] 57.129997  
LogBlueprintUserMessages: [BP\_Test] 36.809998  
LogBlueprintUserMessages: [BP\_Test] 33.200001  
LogBlueprintUserMessages: [BP\_Test] 25.09  
LogBlueprintUserMessages: [BP\_Test] 67.07  
LogBlueprintUserMessages: [BP\_Test] 91.650002  
LogBlueprintUserMessages: [BP\_Test] 23.519999  
LogBlueprintUserMessages: [BP\_Test] 89.970001  
LogBlueprintUserMessages: [BP\_Test] 84.189995  
LogBlueprintUserMessages: [BP\_Test] 62.82  
LogBlueprintUserMessages: [BP\_Test] 71.769997  
LogBlueprintUserMessages: [BP\_Test] 59.969997  
LogBlueprintUserMessages: [BP\_Test] 78.769997  
LogBlueprintUserMessages: [BP\_Test] 48.289997  
LogBlueprintUserMessages: [BP\_Test] 45.950001  
LogBlueprintUserMessages: [BP\_Test] 70.93  
LogBlueprintUserMessages: [BP\_Test] 64.830002  
LogBlueprintUserMessages: [BP\_Test] 80.32

---

<div class="post-metadata">

**Author:** ![MOSF](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MOSF](https://forums.unrealengine.com/u/MOSF)\
**Post date:** [June 7, 2020, 9:43am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/10 "2020-06-07T09:43:08Z")

</div>

That solution should work, but it doesn’t. Quite weird…  
You can try like this, but you will have a string output:

 ![string.PNG.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/e/9/e9b40c3fee3a994ae74852fc793675eae2e3d138.jpeg)

or you can use “to text (float)”, expand it by clicking on the down arrow, and set the maximum fractional digits to 2, but you will have a text value.

---

<div class="post-metadata">

**Author:** ![GarnerP57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GarnerP57](https://forums.unrealengine.com/u/GarnerP57)\
**Post date:** [June 7, 2020, 10:14am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/11 "2020-06-07T10:14:39Z")

</div>

Rounding a float is not that simple. Floats are by design not 100% accurate so if you want a 100% accurate number you will need to use integers. Floats are used because they can display very large numbers without requiring a lot of memory and overhead.

So you have two options either format the float using “Float To Text” as mentioned above or convert the float to an Integer.

---

<div class="post-metadata">

**Author:** ![Apollo1444](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Apollo1444](https://forums.unrealengine.com/u/Apollo1444)\
**Post date:** [June 7, 2020, 4:01pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/12 "2020-06-07T16:01:19Z")

</div>

> [@GarnerP57](#):
>
> Rounding a float is not that simple. Floats are by design not 100% accurate so if you want a 100% accurate number you will need to use integers. Floats are used because they can display very large numbers without requiring a lot of memory and overhead.
> 
> So you have two options either format the float using “Float To Text” as mentioned above or convert the float to an Integer.

Got it! Thanks a lot, guys!  
Currently I guess “Float To Text” will be good enough for me.

---

<div class="post-metadata">

**Author:** ![gothicjb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gothicjb](https://forums.unrealengine.com/u/gothicjb)\
**Post date:** [July 3, 2021, 5:09pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/13 "2021-07-03T17:09:13Z")

</div>

For anyone else coming here late to the game… the Float to Text to Float if you need it is:  
float x = FCString::Atof(\*FString::SanitizeFloat(FMath::FRandRange( min, max )).Left(precision + 2));

replace “FMath::FRandRange( min, max )” with your float.

---

<div class="post-metadata">

**Author:** ![DaveTheDND](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davethednd/32/88706_2.png) [@DaveTheDND](https://forums.unrealengine.com/u/DaveTheDND)\
**Post date:** [January 18, 2022, 4:10pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/14 "2022-01-18T16:10:26Z")

</div>

Hey there, just found this thread I I’ve found a quite elegant solution. I’ve created a macro that looks like the following:

 ![DecimalPoints](https://d3kjluh73b9h9o.cloudfront.net/original/3X/a/3/a358056351518420f295343c5c581c85a6bb87fa.jpeg)

---

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [January 19, 2022, 6:30pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/15 "2022-01-19T18:30:40Z")

</div>

Isn’t there already a macro for this?

 ![Screenshot_20220119-142903_Chrome](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/4/b4997e02f6d14092eec56f7749fd978df4f5b643.jpeg)

---

<div class="post-metadata">

**Author:** ![unrealsumon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@unrealsumon](https://forums.unrealengine.com/u/unrealsumon)\
**Post date:** [April 29, 2022, 3:28am UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/16 "2022-04-29T03:28:02Z")

</div>

Try this.

 ![floatPrecision](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/c/b/8cb57d562767660a2da6eec68497fd678c68b65c.png)

---

<div class="post-metadata">

**Author:** ![parakyl](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/parakyl/32/1086537_2.png) [@parakyl](https://forums.unrealengine.com/u/parakyl)\
**Post date:** [June 14, 2023, 7:20pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/17 "2023-06-14T19:20:06Z")

</div>

Just adding this as it ranks top Google for this problem:  
For 1 decimal place:  
Multiply by 10  
Truncate  
Divide by 10

2 decimals use 100, 3 use 1000 etc

---

<div class="post-metadata">

**Author:** ![Oli](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/oli/32/759389_2.png) [@Oli](https://forums.unrealengine.com/u/Oli)\
**Post date:** [September 6, 2023, 5:58pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/18 "2023-09-06T17:58:14Z")

</div>

I second that this is a smart and flexible approach, considering i’m not aware (as a beginner) of any native node to handle such. I tested this macro and works all good.

I added extra output pins to this macro for my own needs (e.g. String type which plug in straight to the PrintDebug = saves some extra nodes to keep things clean).

Such macro can become a “Value Formater”.

Thank you for sharing!

---

<div class="post-metadata">

**Author:** ![Mogno](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mogno](https://forums.unrealengine.com/u/Mogno)\
**Post date:** [September 8, 2023, 3:10pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/19 "2023-09-08T15:10:54Z")

</div>

You can _ **divide the round output by in** t_ instead of _multiplying by float_ to resolve this issue.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/4/1a44fe156348feca56a70fd38c6165ed00cab72c.png)

Here is the code snippet for easy grab.

> **[Limit float decimal digits | Unreal engine Code Snippet](https://dev.epicgames.com/community/snippets/7NAX/unreal-engine-limit-float-decimal-digits)**

---

<div class="post-metadata">

**Author:** ![MaverickHter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MaverickHter](https://forums.unrealengine.com/u/MaverickHter)\
**Post date:** [May 5, 2024, 9:12pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/20 "2024-05-05T21:12:14Z")

</div>

I solved this by using this division node, taking the integer value and concatenating with the truncated remaining. One decimal, multiply by 10, two decimals, 100 etc…

 ![imagem_2024-05-05_181024075](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/d/d/add0b904ead6d314d3035e2a79bcb96226b75c0e.png)

---

<div class="post-metadata">

**Author:** ![Sly.k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sly.k](https://forums.unrealengine.com/u/Sly.k)\
**Post date:** [May 6, 2024, 7:11pm UTC](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299/21 "2024-05-06T19:11:53Z")

</div>

LowEntry Extended Lirbary has a node for that

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/c/3/cc3858b118f3006009a69e13929452a90f3b9542.png)

It’s free here: [https://www.unrealengine.com/marketplace/en-US/product/low-entry-extended-standard-library](https://www.unrealengine.com/marketplace/en-US/product/low-entry-extended-standard-library)  
It’s a well supported plugin.

[Next page](https://forums.unrealengine.com/t/solved-how-to-round-floats-0-234378996-0-23/144299.md?page=2)
