Skip to main content

$formatInteger

$formatInteger(number?, picture) -> string
Compact type signature<n-s:s>

If number is omitted, the current context value is used.

Browse categories

Source: JSONata

Documentation

Casts the number to a string and formats it to an integer representation as specified by the picture string.

The behaviour of this function is consistent with the two-argument version of the XPath/XQuery function fn:format-integer as defined in the XPath F&O 3.1 specification. The picture string parameter defines how the number is formatted and has the same syntax as fn:format-integer.

Examples

Basic usage

  • $formatInteger(2789, 'w') => "two thousand, seven hundred and eighty-nine"
  • $formatInteger(1999, 'I') => "MCMXCIX"

Format a number as a Roman numeral (picture string)

Input

This example uses the claims-lines example input. The expression reads the third claim line's lineNumber and formats it as a Roman numeral.

Example input

JSON
[
{
"claimId": "clm-2001",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 110,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2001",
"lineNumber": 2,
"serviceCode": "PROC-020",
"serviceDisplay": "imaging study",
"units": "1",
"unitPrice": 350,
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
]
},
{
"claimId": "clm-2001",
"lineNumber": 3,
"serviceCode": "PROC-030",
"serviceDisplay": "lab panel",
"units": 2,
"unitPrice": 40,
"allowedAmount": 70,
"modifiers": []
},
{
"claimId": "clm-2002",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 115,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2002",
"lineNumber": 2,
"serviceCode": "PROC-040",
"serviceDisplay": "counseling",
"units": 3,
"unitPrice": 60,
"allowedAmount": 150,
"modifiers": [
"MOD-D"
]
}
]

Expression

$formatInteger($[2].lineNumber, "I")

Result

"III"