Loading TOC...

xdmp.formatNumber

xdmp.formatNumber(
   $value as xs.numeric[],
   [$picture as String?],
   [$language as String?],
   [$letter-value as String?],
   [$ordchar as String?],
   [$zero-padding as String?],
   [$grouping-separator as String?],
   [$grouping-size as Number?]
) as String

Summary

Returns a formatted number value based on the picture argument. The difference between this function and the W3C standards fn:format-number function is that this function imitates the XSLT xsl:number instruction, which has richer formatting options than the fn:format-number function. This function can be used for spelled-out and ordinal numbering in many languages. This function is available in XSLT as well as in all dialects of XQuery and Server-Side JavaScript.

Parameters
$value The given numeric $value that needs to be formatted.
$picture The desired string representation of the given numeric $value. The picture string is a sequence of characters, in which the characters represent variables such as, decimal-separator-sign, grouping-sign, zero-digit-sign, digit-sign, pattern-separator, percent sign and per-mille-sign. For details on the picture string, see http://www.w3.org/TR/xslt20/#date-picture-string. Unlike fn:format-number(), here the picture string allows spelled-out (uppercase, lowercase and Capitalcase) formatting.
$language The desired language for string representation of the numeric $value. An empty sequence must be passed in even if a user doesn't want to specifiy this argument.
$letter-value Same as letter-value attribute in xsl:number. This argument is ignored during formatting as of now. It may be used in future. An empty sequence must be passed in even if a user doesn't want to specifiy this argument.
$ordchar If $ordchar is "yes" then ordinal numbering is attempted. If this is any other string, including an empty string, then then cardinal numbering is generated. An empty sequence must be passed in even if a user doesn't want to specifiy this argument.
$zero-padding Value of $zero-padding is used to pad integer part of a number on the left and fractional part on the right, if needed. An empty sequence must be passed in even if a user doesn't want to specifiy this argument.
$grouping-separator Value of $grouping-separator is a character, used to groups of digits, especially useful in making long sequence of digits more readable. For example, 10,000,000- here "," is used as a separator after each group of three digits. An empty sequence must be passed in even if a user doesn't want to specify this argument.
$grouping-size Represents size of the group, i.e. the number of digits before after which grouping separator is inserted. An empty sequence must be passed in even if a user doesn't want to specifiy this argument.

Usage Notes

Most, but not all formatting combinations work. The following table shows formatting options by language, and lists what is supported and what is not.

LanguageNumeric CardinalsNumeric OrdinalsSpelled Out CardinalsSpelled Out Ordinals
enYesYesYesYes
frYesYesYesNo
itYesYesYesNo
deYesNoYesYes
ruYesNoYesNo
esYesYesYesNo
arYesYesYesNo
zhYesYesYesYes
koYesYesYesYes
faYesNoYesNo
nlYesYesYesYes
jaYesYesYesYes
ptYesYesYesNo

Example

var res = new Array();
res.push(xdmp.formatNumber(29,"01","en","",null,'0',",",3));
res.push(xdmp.formatNumber(09,"W","en","",null,'"',",",3));
res.push(xdmp.formatNumber((5),"w","es",null,null,"0",",",3));
res.push(xdmp.formatNumber((5),"w","fr",null,null,"0",",",3));
res;
=>
["29", "NINE", "cinco", "cinq"]
 

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy