Formatting Currency Issues

Hi, I’m trying to format currencies using this module. It doesn’t format, instead, it gives the value. Here is my code:

local DataStore2 = require(game.ServerScriptService.DataStore2)
local MarketplaceService = game:GetService("MarketplaceService")
local FormatNumber = require(game.ServerScriptService.FormatNumber)

local defaultCashValue = 0

	local coinsDataStore = DataStore2("Coins", plr)

	local cash ="IntValue")
	cash.Name = "Cash"
	local function coinsUpdated(updatedValue)
		cash.Value = coinsDataStore:Get(updatedValue)
		game.ReplicatedStorage.UpdateClientCurrency:FireClient(plr, coinsDataStore:Get(defaultCashValue))
		FormatNumber.FormatCurrency(updatedValue, "$")



1 Like

The function returns a string value.
The script doesn’t do anything with the string as you didn’t assign it to a variable.
Works on my side:

print(FormatNumber.FormatCurrency(1234.56, "$"));


1 234,56 $

So how do i format the amount of cash someone has?

Hey with DataStore2 You’re updating the data store, which then updates the value.

Say you want special formatting to appear then I recommend instead of using an IntValue, use a StringValue.

Then on your CoinsUpdated function instead of it just being

You can add this on, cash.Value = coinsDataStore:Get(updatedValue)…"$"

So say you’re coinsDataStore is 500, the cash.value formatting will now have it appear as 500$

Now say you want it so, “I want 1000$ to appear as 1,000$”. You will need to run checks on what the current coinsdatastore is, for example for every three 0’s add a “,”. To my knowledge this works perfectly for me since when this function is called it is editing the “cash.Value” which is a String Value.
However I must apologise that I am unaware of what “FormatNumber.FormatCurrency” is as I have personally never seen this in the ds2 module before, I hope what I posted above fixed your issue! :slightly_smiling_face:

I switched it to a stringvalue, however, it didn’t format it.

That’s odd. Since it’s now a String Value you should be able to make it Format, and appear how you want. (As the “Cash” Value). Does the DollarSign not appear after the numbers? e.g Instead of 500 it would now be “500$”

It doesn’t appear. Only the value, like 500

Try this instead,
CurrentCash = coinsDataStore:Get(UpdatedValue)
Formatting = tostring(CurrentCash)…"$"
cash.Value = Formatting

What? What do you mean? I don’t understand that

So the CurrentCash Variable will be the holder for your coinsDataStore amount, If this players coin store had 500 then CurrentCash would be 500. Then for formatting I am turning this variable from integer to string using “tostring(variable)” with adding “…" afterwards, essentially i am forcing it to be a string. Which would make the current Formatting variable have "500”, then afterwards I am changing the Cash String Value to be what the Formatting Variable is, this means everytime your coinsDataStore has an update to it, it will run this function which should hopefully make Cash appear with an “$” at the end.

What don’t you understand?
Please clearify.
What did you expect it to happen? What is your expected value?

This is redundant, this ain’t C or C#, .. automatically converts from integers to strings. You don’t need tostring to convert values.

Still got the same result as mentioned before.

It’s not doing the format that your module is supposed to do.

string.format("%.2f $", 1234.56)
sorry for the short answer i really do not have the effort to explain string formatting right now

Read more here:

Where would I put this line? 30 char

What do you mean by not doing the format, and did you try to print it to see does it work? It should’ve returned a string value. Try testing it:

print(FormatNumber.FormatCurrency(1234.56, "€") == "1 234,56 €");

Does it return true or false?

-- 1 234,56 €
FormatNumber.FormatCurrency(1234.56, "€")

is basically equivalent to this in C#

// 1.234,56 €