Money type

Money type documentation.

Overview

This type is designed to store decimal money amounts and offers options for rounding, specifying the number of decimals, displaying thousands separators, and indicating currency symbols.

As of now, this type does not support more than 4 decimals. However, this limitation is expected to be resolved in the near future.

Available features

NameSupported
Many multiplicityyes
Default valuesyes
Unique flagno
Required flagyes
Indexable flagyes
Sensitive flagyes
Calculated valueyes
Automatic initializationno
Calculated initial valueno
Aggregationyes
Default type rulesyes
Default display optionsyes

Type rules

Minimum value

The minimum value (inclusive).

Maximum value

The maximum value (inclusive).

Limit decimals

This feature enables the limitation of the number of decimals. This limitation will be applied at the data level, meaning numbers will be stored in the database with the specified number of decimals, and any additional decimals will be discarded. If you wish to retain the additional decimals for display purposes while limiting their storage, you should configure these settings within the display options.

When you opt to limit the number of decimals, the following choices will be presented:

  • Number of Decimals: This indicates the number of decimals to be stored. It can range from 0 to 4.

  • Extra Decimals Action: This specifies the action to take when there are more decimals than the limit permits. The available options include:

    • Round: Rounding will be used to limit the decimals.
    • Truncate: Truncation will be applied to the trailing decimals.
    • Throw Error: An error will be triggered if an attempt is made to set more decimals than the allowable limit.

Display options

  • Symbol: This represents the currency symbol that will be displayed in read-only mode.

  • Show Thousands Separator: If this flag is enabled, the thousands separator will be displayed in read-only mode. Please note that this flag does not affect edit mode.

  • Limit Number of Decimals: This feature allows the limitation of displayed decimals. It operates at the UI level and does not impact validation rules or database storage. Consequently, these options only apply to read-only mode.

    When you choose to limit the number of decimals, the following choices will be presented:

    • Number of Decimals: This denotes the count of decimals to be displayed. It can range from 0 to 4.
    • Extra Decimals Action: This specifies the action to take when there are more decimals than the set limit. The available options include:
      • Round: Rounding will be used to limit the decimals.
      • Truncate: Truncation will be applied to the trailing decimals.

REST API

Read format

The format is a number:

"averageSalary": 80000.00

Write format

To set the value, provide a number:

"averageSalary": 100000.00

JavaScript API

Read format

The val() method within the wrapper will return a number:

// this will print something like "salary: 80000.000000"
log('salary: '+record.field('averageSalary').val());

Write format

To set the value, provide a number:

record.field('averageSalary').val(100000.00);

If you provide something that isn’t a number, the field will be set to null.

Wrapper method:
toHex()

The toHex() method returns string of hexadecimal representation of the value or empty ('') if null.

Returns

string - Hex value of number.

Samples
// prints the hex value of a money field
var record = sys.data.findOne('projects', {name: 'Point-to-point link'});
sys.logs.debug('project budget hex: '+record.field('budget').toHex());


Wrapper method:
format(options)

Returns a string representing the formatted number value or an unformatted string.

Parameters
NameTypeRequiredDescription
optionsobjectnoThese parameters are used to format the value. If left empty, the default display options will be used for formatting.
- thousandsSeparator: If set to “true,” a thousands separator will be displayed; if set to “false,” it won’t.
- limitNumberOfDecimals: If set to “true,” the number of decimals will be limited; if set to “false,” it won’t.
- numberOfDecimals: The count of decimals to be displayed. Default is 2.
- limitRuleType: The rule to use when limiting decimals, either “TRUNCATE” or “ROUND.” Default is “TRUNCATE.”
Returns

string - String of formatted value of number.

Samples
// prints the formated value of a money field
var inv = sys.data.findById('invoices', '579f5929e4b043b8ce4519b6');
sys.logs.debug('total: ' + inv.field('total').format({
  'thousandsSeparator': true, 
  'limitNumberOfDecimals': true, 
  'numberOfDecimals': 2
  })
);


Export/Import

Export format

The export format is an decimal number:

"moneyField1","moneyField2"
"0.872","27810.0028"

Import format

The import format is a string with an decimal number:

"moneyField1","moneyField2"
"0.872","27810.0028"

Queries

For more information, please refer to the Query Language Documentation.

Available operators

OperatorSupported
equalsyes
notEqualsyes
emptyyes
notEmptyyes
likeno
greateryes
greaterOrEqualsyes
lessyes
lessOrEqualsyes
betweenyes
currentUserFieldno

Query formats

You should provide the number. For instance:

// finds skills with an average salary greater or equals to 80000.00 
var records_sample = sys.data.find('skills', {'averageSalary': 'greaterOrEquals(80000.00)'});
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds skills with an average salary greater or equals to 80000.00 
var query_sample = sys.data.createQuery('skills')
    .field('averageSalary').greaterOrEquals(80000.00)
var records_sample = sys.data.find(query_sample);
log('total: '+records_sample.count());
while (records_sample.hasNext()) {
    log(records_sample.next().label());
}
// finds skills with an average salary greater or equals to 80000.00 
GET /data/contacts?averageSalary=greaterOrEquals(80000.00)

Aggregate queries

Please refer to the Aggregate Queries Documentation for more detailed information.

Available operators

OperatorSupported
sumyes
avgyes
firstyes
lastyes
minyes
maxyes

UI queries

Please refer to the UI Queries Documentation for more detailed information.

Matching of values

PropertyDescription
Matching operatorequals

Available operators

OperatorSupported
Many valuesyes
Greaterno
Greater or equalsno
Lessyes
Less or equalsyes
Betweenyes