# "string to math expression"

**URL:** <https://forums.unrealengine.com/t/string-to-math-expression/35413>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [July 14, 2015, 9:41pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413 "2015-07-14T21:41:57Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![t0b4cc0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@t0b4cc0](https://forums.unrealengine.com/u/t0b4cc0)\
**Post date:** [July 14, 2015, 9:41pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/1 "2015-07-14T21:41:57Z")

</div>

Hi!

Is there any way to turn strings into math expressions in blueprint?

For example I have as string: “5\*7+1-99/3” and would like to let it calculate the result.

Thought about sth like a math expression node with a string input on the name.

regards

\*\*Edit: I get that I have to convert this: 5_7+1-99/3 into this: (5_7)+1-(99/3), that is not the problem.

The problem is that I can not find anything in blueprints that takes this at runtime. Not even with correct brackets.\*\*

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_72f63869](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_72f63869](https://forums.unrealengine.com/u/anonymous_user_72f63869)\
**Post date:** [July 15, 2015, 2:55am UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/2 "2015-07-15T02:55:28Z")

</div>

Have you tried the “String to int” node? Not sure if that is what you need.

---

<div class="post-metadata">

**Author:** ![JmDevTx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JmDevTx](https://forums.unrealengine.com/u/JmDevTx)\
**Post date:** [July 15, 2015, 3:36am UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/3 "2015-07-15T03:36:53Z")

</div>

> [@fp0707;332611](#):
>
> Have you tried the “String to int” node? Not sure if that is what you need.

t0b4cc0, why do you have a string containing math equations, perhaps there is another way to accomplish what you are trying to do.

---

<div class="post-metadata">

**Author:** ![t0b4cc0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@t0b4cc0](https://forums.unrealengine.com/u/t0b4cc0)\
**Post date:** [July 15, 2015, 8:25am UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/4 "2015-07-15T08:25:04Z")

</div>

> [@Jamendxman3;332637](#):
>
> t0b4cc0, why do you have a string containing math equations, perhaps there is another way to accomplish what you are trying to do.

indeed that is a good question, and usually you dont come around math equations in strings. I am working on a genetic algorithm. In short, i have a bitcode. like 00010101011010101, and the first 4, 0001 mean 1, the next few (0101) could mean + for example. the bytecode is stored in strings (I seperate them per comma like “0001,1010,…” i could not find a way to use custom structs in bp)  
It was just to easy for me to translate the bytecode to strings of math operators and numbers.

Anyways, I probably should figure out how to make a decent calculator. (only needs to be for basics, + - \* /)

---

<div class="post-metadata">

**Author:** ![JmDevTx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JmDevTx](https://forums.unrealengine.com/u/JmDevTx)\
**Post date:** [July 15, 2015, 8:39am UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/5 "2015-07-15T08:39:26Z")

</div>

For a basic calculator you just need a few booleans, two variables to hold the previous number and the number you are adding/subtracting/etc… and a bunch of branches, if IsAdding is true, then add #1 + #2 (set #1 to the result of the math), if IsMultiplying is true, then multiply them, and so on…

---

<div class="post-metadata">

**Author:** ![t0b4cc0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@t0b4cc0](https://forums.unrealengine.com/u/t0b4cc0)\
**Post date:** [July 15, 2015, 11:38pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/6 "2015-07-15T23:38:28Z")

</div>

how would you go about following the rules of math with sth like this:

5\*7-3/8+2

(so that it correctly calculates 3/8 before 8+2)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0df12f74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0df12f74](https://forums.unrealengine.com/u/anonymous_user_0df12f74)\
**Post date:** [July 16, 2015, 12:04am UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/8 "2015-07-16T00:04:40Z")

</div>

> [@t0b4cc0;333430](#):
>
> how would you go about following the rules of math with sth like this:
> 
> 5\*7-3/8+2

Separate it into sections and use BP nodes like this:

create a multiply node (float \* float) and enter (5 \* 7)  
create a division node (float / float) and enter (3 / 8)  
create a minus node (float - float) and plug the output from the multiply in the top pin, division output into the second pin  
create a plus node (float + float) and plug the result from the minus node in the top pin, and enter 2 for the second pin’s value

-or-

You can use a custom Math node to do this if you’d like, in that case you need to follow the following convention and enter this as the text:

(5 \* 7) - (3 / 8) + 2

That should work properly. You always need to evaluate any multiplication or division separately from adding/subtracting, adding in the brackets forces the compiler to do that equation first.

---

<div class="post-metadata">

**Author:** ![t0b4cc0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@t0b4cc0](https://forums.unrealengine.com/u/t0b4cc0)\
**Post date:** [July 16, 2015, 9:46am UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/9 "2015-07-16T09:46:32Z")

</div>

> [@;333449](#):
>
> adding in the brackets forces the compiler to do that equation first.

I totally get that, but I do not know how to make a _BP_ solve it after adding brackets.  
In code I could write that out and let it calculate. (with a library) \*\*I can not find anything in blueprints that takes this at runtime. Not even with correct brackets. \*\* thats why I asked in my initial post if there is something like the math expression node that can be fed information at runtime.

---

<div class="post-metadata">

**Author:** ![KVogler](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KVogler](https://forums.unrealengine.com/u/KVogler)\
**Post date:** [July 16, 2015, 12:18pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/10 "2015-07-16T12:18:10Z")

</div>

> [@](#):
>
> I totally get that, but I do not know how to make a _BP_ solve it after adding brackets.

What you would need is a parser that evaluates your string expressions.  
While Im quite good at writing all types of parsers (kind of hobby), I dont think its feasible in BP.

The closest thing that would be doable in Bp with realative ease would be a stack based parser and using reverse polish notation in the expression.  
Then it is just a question of how to tokenize your string.  
The idea is that you end up with an array that contains your sequence of operators and operands, like:  
“3”  
“4”  
“+”  
… which represents “4+3” in inline notation.  
The reverse polish notation completely avoids the problems of resolving (nested) brackets…

Dang, now I wanna make something like this just for fun 🙂

---

<div class="post-metadata">

**Author:** ![Grogger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Grogger](https://forums.unrealengine.com/u/Grogger)\
**Post date:** [July 16, 2015, 3:22pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/11 "2015-07-16T15:22:36Z")

</div>

I have made a Blueprint parser that can do this (it’s part of the dialogue system in my signature). I had started a thread about putting it up on the marketplace as a standalone thing [here](https://forums.unrealengine.com/showthread.php?71780-GAUGING-INTEREST-Blueprint-only-embedded-scripting-language), but it didn’t receive much attention.

At any rate, making a parser to convert a string to a mathematical expression is what you’ll need to do I’m afraid. I used the [Shunting Yard algorithm](http://www.wikiwand.com/en/Shunting-yard_algorithm) for this (it’s rather simple if you don’t aim to have short-circuiting operators like and/or/?: as I did in my interpreter).

Let me know if you go the route of making a parser and need a hand with it 🙂

---

<div class="post-metadata">

**Author:** ![t0b4cc0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@t0b4cc0](https://forums.unrealengine.com/u/t0b4cc0)\
**Post date:** [July 16, 2015, 8:40pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/12 "2015-07-16T20:40:55Z")

</div>

> [@Grogger;333885](#):
>
> Let me know if you go the route of making a parser and need a hand with it 🙂

when i posted this i started to make a parser already.

i just thought while doing it, that the math expression node allowing a string input as expression during runtime would be nice to have

> [@KVogler;333766](#):
>
> While Im quite good at writing all types of parsers (kind of hobby), I dont think its feasible in BP.

wow since you seem to be a fan, ill upload mine to dropbox, have a look at it, i dont think its efficient but it does the job. would be nice to hear back from you. (for my genetic algorithm i only have single digit numbers and the only operators are ±\*/ so it was quite easy, i had more problems doing the math since it took me a while to realize that find item \* in string array does what i expect from a windows search instead of finding the multiply operator index)

> **[calculator.rar](https://www.dropbox.com/s/q6ctfmo7kewuizr/calculator.rar?dl=0)**
>
> Shared with Dropbox

only allows single digit numbers, the 4 basic math operators (+,-,/,x), the variable “rechnung” holds the calculation to test.

---

<div class="post-metadata">

**Author:** ![Grogger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Grogger](https://forums.unrealengine.com/u/Grogger)\
**Post date:** [July 16, 2015, 8:52pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/13 "2015-07-16T20:52:32Z")

</div>

> [@t0b4cc0;334097](#):
>
> when i posted this i started to make a parser already.
> 
> i just thought while doing it, that the math expression node allowing a string input as expression during runtime would be nice to have

Ah ok, it certainly would have saved me a bunch of time as well 🙂

---

<div class="post-metadata">

**Author:** ![DELGOODIE](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/delgoodie/32/1103781_2.png) [@DELGOODIE](https://forums.unrealengine.com/u/DELGOODIE)\
**Post date:** [February 9, 2024, 6:18am UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/14 "2024-02-09T06:18:49Z")

</div>

If anyone is still struggling with this, there is a build in function

FMath::Eval

---

<div class="post-metadata">

**Author:** ![MhjStudio](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mhjstudio/32/1082519_2.png) [@MhjStudio](https://forums.unrealengine.com/u/MhjStudio)\
**Post date:** [October 10, 2025, 2:09pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/15 "2025-10-10T14:09:16Z")

</div>

after destorying my self i made it  
It 100 in bluprints  
it works like c++  
take look

> **[GitHub - amiralimehr/ECLIPSE-Math-engine-Algorithm-unreal-engine- at engine](https://github.com/amiralimehr/ECLIPSE-Math-engine-Algorithm-unreal-engine-/tree/engine)**
>
> engine

---

<div class="post-metadata">

**Author:** ![AsdPtion](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AsdPtion](https://forums.unrealengine.com/u/AsdPtion)\
**Post date:** [July 20, 2026, 7:50pm UTC](https://forums.unrealengine.com/t/string-to-math-expression/35413/16 "2026-07-20T19:50:43Z")

</div>

I downloaded you Uasset to \content\ folder, but UE5.7 on win64 does not see it. may be you know whats the trouble?
