Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (112 sloc) 5.01 KB
title categories
Format prices in Adobe Campaign (NL.Locale cheatsheet)
adobe campaign



var x = 1234567.89;

// with NL.Locale
loadLibrary('xtk:shared/nl.js'); // for NL
NL.require('/nl/core/jsspcontext.js'); // for NL.Locale
NL.Locale.formatNumber(x) // 1,234,568 (uses default settings from NL.session.locale, see next chapter)
NL.Locale.formatNumber(x, {addSymbol: true}) // $1,234,568

var formatUS = {pattern: '¤#,##0.00', groupSymbol: ',', decimalSymbol: '.', symbol: '$'};
NL.Locale.formatNumber(x, formatUS) // $1,234,567.89

var formatFR = {pattern: '#,##0.00 ¤', groupSymbol: ' ', decimalSymbol: ',', symbol: ''};
NL.Locale.formatNumber(x, formatFR) // 1 234 567,89 €

// with Format
loadLibrary('xtk:common.js'); // for Format
Format.formatNumber(x) // 1,234,567.89

NL.Locale doc

 * @param {Number} number the number to format
 * @param {mixed} format is the format to use:
 *   string: pattern to use
 *   number: number of decimal places for the formatted value
 *   JSON object:
 *     addSymbol
 *     pattern:
 *       0 - represent any digit
 *       # - represent any digit, 0 is shows as absent
 *       . - decimal separator (replaced by format.decimalSymbol)
 *       - - minus sign (replaced by format.minusSign)
 *       , - grouping separator (replaced by format.groupSymbol)
 *       ¤ - currency sign (\u00A4) (replaced by format.symbol)
 * @param {String, optional} defaultReturn String to use when value is not a valid number
 * @return string
 * @throws {Error} When value is not a valid number and defaultReturn is not defined.
function formatNumber(value, format, defaultReturn)

from \usr\local\neolane\nl6\datakit\xtk\fra\js\shared\dataTypes.js

Get your locale regional settings from the current locale NL.session.locale. Example for the en-us locale:

      "longDate":"%A, %D %B, %4Y",
      "time":"%I:%2N:%2S %P",
      "shortDateTime":"%2M/%2D/%4Y %I:%2N:%2S %P",
      "AmPm":["AM", "PM"],
      "shortQuarter":"Q%C %4Y",
      "longQuarter":"%Q %4Y",
      "longMonth":"%B %4Y",
      "longWeek":"%4V - Week %2W",
      "daysName":["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
      "shortDaysName":["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
      "monthsName":["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
      "quartersName":["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"],
      "timeSpanUnits":{"seconds":"s", "minutes":"mn", "hours":"h", "days":"d", "months":"m", "years":"y"},
      "booleanStrings":{"true":"true", "false":"false"},
         "dataSize":[{"symbol":"B", "factor":1}, {"symbol":"kB", "factor":1024}, {"symbol":"MB", "factor":1048576}, {"symbol":"GB", "factor":1073741824}],
         "count":[{"symbol":"", "factor":1}, {"symbol":"k","factor":1000}, {"symbol":"M","factor":1000000},  {"symbol":"G","factor":1000000000}]

The regional settings are defined as a local var _regionSettings in dataTypes.js.

All NL.Locale functions and vars:

NL.Locale.getFormat = function(name, options)
NL.Locale.defaultLanguage = 'en-us';
NL.Locale.getLocale = function (language)
NL.Locale.getValidLanguageFromHttpHeader = function (header, validityCheck)
NL.Locale.NL.session.locale = getLocale(locale);
NL.Locale.parseBoolean =  function(value, defaultReturn)
NL.Locale.formatBoolean = function(value, format, defaultReturn)
NL.Locale.parseString =  function(value, defaultReturn)
NL.Locale.parseNumber = function(value, defaultReturn)
NL.Locale.parseInt =  function(value, defaultReturn)
NL.Locale.formatNumber =  function(value, format, defaultReturn)
NL.Locale.formatInt =  function(value, format, defaultReturn)
NL.Locale.formatPercent = function (value, decimalPlaces, defaultReturn)
NL.Locale.formatDataSize = function (value, format, defaultReturn)
NL.Locale.formatWithUnit = function (value, significantFigures, unit, defaultReturn)
NL.Locale.getMonthName = function (arg)
NL.Locale._splitFormat = function (format)
NL.Locale.parseDateTime =  function(value, format, defaultReturn)
NL.Locale.parseDateOnly =  function(value, format, defaultReturn)
NL.Locale.parseTime =  function(value, format, defaultReturn)
NL.Locale.formatDateTime =  function(value, format, defaultReturn)
NL.Locale.formatDateOnly =  function(value, format, defaultReturn)
NL.Locale.formatTime =  function(value, format, defaultReturn)
NL.Locale.formatDatePartial =  function(datePartial, interval, format)
NL.Locale.formatTimeSpan =  function(value, format, defaultReturn)
You can’t perform that action at this time.