Currency

Scripting with the Currency struct.

The Currency struct is a representation of monetary value.

Fields & Properties

Name
Description
Type
Access

identity

The identity of the currency.

CurrencyIdentity

public

value

The currency value.

Currency.Value

public

stringValue

The value as a string.

string

public

Creating a Currency

To create a Currency, you need a reference to a Currency Identity.

// Create a currency with 0 value
Currency myCurrency = new Currency(myCurrencyIdentity, 0);

Managing Values

A Currency uses the Value struct to support all numeric value types. The numeric type used by a Currency depends on it's CurrencyIdentity (int, float, or decimal).

If you have strictCurrencyValueTypes enabled in Settings, this will throw an error when trying to change the value using the incorrect numeric type.

Set the Value

To set a new value, you can use the SetValue method.

// Sets the value to 100
myCurrency.SetValue(100);

Alternatively, you can use SetValueWithConversion, which is similar to SetValue, except it ignores the strictCurrencyValueTypes settings field.

myCurrency.SetValueWithConversion(100);

Operators

You can use operators to perform mathematical operations with currencies. Strict value types may apply.

// Add 100
myCurrency += 100;

// Subtract 100
myCurrency -= 100;

// Double the value
myCurrency *= 2;

// Halve the value
myCurrency /= 2;

Last updated