Download

What is the preferred way of storing currencies?

Hi All,

Couldn’t find anything in the UE4 documentation regarding storing currencies.

Is that correct that there’s no anything like Decimal type in Python?

Should I use a third party solution like this one?

Thanks!

I think you best shot it to use a library like the one you provided.

I have implemented my own class in a plugin for this.
I’ve added to the Engine some month ago, I have a FDecimal type which uses Intel’s RDFP Math Library which is IEEE-754 compliant: https://software.intel.com/sites/default/files/article/144639/readme.txt

It works exactly like C# Decimal type; can store up to 29 digits of a decimal value, like:

FDecimal Gold = FDecimal(“999.999.999.999.999.999.999.999.999,99”);

Gold -= 5000;
Gold += 5.0;

Can convert from FString, int32, uint32, int64, uint64, float or double, all to decimal…
It is serializing correctly, I just didn’t work on optimizing network Replication for it just yet.
I did this stuff because storing “coins” or any real world currency as float or double is really really a bad idea :slight_smile:

Too bad C++ doesn’t have this kind of thing built-in:/

Thanks for the replies!

Bruno, do you plan to publish the plugin on GitHub? I am planning to just go with the solution I’ve posted in the topic post and use strings for replication.

I don’t think decimal type should be in C++ standard libraries but was surprised that it is not among Unreal Engine types.

Thanks again!