Jump to content
hoverguy

[Snippet] Currency Formatting Function

Recommended Posts

Description

Function to return currency symbol & passed amount as text

 

Installation

Copy/Paste function file wherever you want, declare it in CfgFunctions, enjoy

 

To Do

Add more language support (more currencies)

Feedback on currency formatting (symbol as prefix or suffix)

 

Code

Spoiler

/*
    Author - HoverGuy
    Description - Function to return currency symbol & passed amount as text
    © All Fucks Reserved
    Parameters
    - 0 - INTEGER - Value
    - 1 - BOOL (OPTIONAL) - true for specific currency input instead of automatic detection (which is less precise)
    - 2 - STRING (OPTIONAL) - If the above is true, it will take specific currency instead of game language automatic detection
    Returns
    Currency symbol & amount as text
*/
params
[
    ["_value",0,[0]],
	["_custom",false,[false]],
	["_currency","USD",[""]],
	["_symbol",[],[]],
	["_text","",[""]]
];

_value = [_value] call BIS_fnc_numberText;

/*
    _symbol array order
    - 0 - STRING - Currency symbol
    - 1 - BOOL - true for symbol as prefix, false for symbol as suffix
*/
if(!_custom) then
{
    _symbol = switch(language) do
    {
	    case "French": {["€",false]};
	    case "German": {["€",false]};
	    case "Russian": {["₽",true]};
	    case "Spanish": {["€",false]};
	    case "Italian": {["€",false]};
        default {["$",true]};
    };
} else {
    _symbol = switch(_currency) do
	{
	    case "USD": {["$",true]};
		case "EUR": {["€",false]};
		case "JPY": {["¥",true]};
		case "GBP": {["£",true]};
		case "AUD": {["$",true]};
		case "CAD": {["$",true]};
		case "CHF": {["CHF",true]};
		case "CNY": {["¥",true]};
		case "SEK": {["kr",false]};
		case "MXN": {["$",true]};
		case "NZD": {["$",true]};
		case "SGD": {["$",true]};
		case "HKD": {["$",true]};
		case "NOK": {["kr",true]};
		case "KRW": {["₩",false]};
		case "INR": {["₹",true]};
		case "RUB": {["₽",true]};
		case "BRL": {["R$",false]};
		case "ZAR": {["R",true]};
	    default {["$",true]};
	};
};

_text = if(_symbol select 1) then {((_symbol select 0) + _value)} else {(_value + (_symbol select 0))};
_text;

 

 

Download

Click Me

  • Like 3

Share this post


Link to post
Share on other sites

Please note that the euro sign is a prefix in English, Dutch and Danish (and probably more, don't know them all).

 

And something which I'm missing in this script is the use of comma's and points to indicate thousands and the decimal mark (https://en.wikipedia.org/wiki/Decimal_mark#Hindu.E2.80.93Arabic_numeral_system).

Especially with bigger numbers (and smaller ones), this might be interesting to add.

  • Like 2

Share this post


Link to post
Share on other sites

Please note that the euro sign is a prefix in English, Dutch and Danish (and probably more, don't know them all).

 

And something which I'm missing in this script is the use of comma's and points to indicate thousands and the decimal mark (https://en.wikipedia.org/wiki/Decimal_mark#Hindu.E2.80.93Arabic_numeral_system).

Especially with bigger numbers (and smaller ones), this might be interesting to add.

Hi,

It is added to the todo list, thanks for the input, was already thinking about adding decimal & thousands separators will definitely be in the next update.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×