-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnumeric-functions.html
192 lines (185 loc) · 27.4 KB
/
numeric-functions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Numeric functions · JSONata</title><meta name="viewport" content="width=device-width, initial-scale=1.0"/><meta name="generator" content="Docusaurus"/><meta name="description" content="## `$number()`"/><meta name="docsearch:version" content="2.0.0"/><meta name="docsearch:language" content="en"/><meta property="og:title" content="Numeric functions · JSONata"/><meta property="og:type" content="website"/><meta property="og:url" content="http://docs.jsonata.org/"/><meta property="og:description" content="## `$number()`"/><meta name="twitter:card" content="summary"/><link rel="shortcut icon" href="/img/jsonata-button.png"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="/js/jsonata-examples.js"></script><script src="/js/scrollSpy.js"></script><link rel="stylesheet" href="/css/main.css"/><script src="/js/codetabs.js"></script></head><body class="sideNavVisible separateOnPageNav"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/"><img class="logo" src="/img/jsonata-button.png" alt="JSONata"/><h2 class="headerTitleWithLogo">JSONata</h2></a><a href="/versions"><h3>2.0.0</h3></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class="siteNavGroupActive"><a href="/overview" target="_self">Docs</a></li><li class=""><a href="http://try.jsonata.org" target="_self">Try</a></li><li class=""><a href="https://github.com/jsonata-js/jsonata" target="_self">GitHub</a></li><li class=""><a href="https://www.npmjs.com/package/jsonata" target="_self">NPM</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><div class="hamburger-menu"><div class="line1"></div><div class="line2"></div><div class="line3"></div></div></div><h2><i>›</i><span>Function Library</span></h2><div class="tocToggler" id="tocToggler"><i class="icon-toc"></i></div></div><div class="navGroups"><div class="navGroup"><h3 class="navGroupCategoryTitle">Getting Started</h3><ul class=""><li class="navListItem"><a class="navItem" href="/overview">Overview</a></li><li class="navListItem"><a class="navItem" href="/using-nodejs">In NodeJS</a></li><li class="navListItem"><a class="navItem" href="/using-browser">In a Web Page</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Language Guide</h3><ul class=""><li class="navListItem"><a class="navItem" href="/simple">Simple Queries</a></li><li class="navListItem"><a class="navItem" href="/predicate">Predicate Queries</a></li><li class="navListItem"><a class="navItem" href="/expressions">Functions and Expressions</a></li><li class="navListItem"><a class="navItem" href="/construction">Result Structures</a></li><li class="navListItem"><a class="navItem" href="/composition">Query Composition</a></li><li class="navListItem"><a class="navItem" href="/sorting-grouping">Sorting, Grouping and Aggregation</a></li><li class="navListItem"><a class="navItem" href="/processing">Processing Model</a></li><li class="navListItem"><a class="navItem" href="/programming">Functional Programming</a></li><li class="navListItem"><a class="navItem" href="/regex">Regular Expressions</a></li><li class="navListItem"><a class="navItem" href="/date-time">Date/Time Processing</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Operators</h3><ul class=""><li class="navListItem"><a class="navItem" href="/path-operators">Path Operators</a></li><li class="navListItem"><a class="navItem" href="/numeric-operators">Numeric Operators</a></li><li class="navListItem"><a class="navItem" href="/comparison-operators">Comparison Operators</a></li><li class="navListItem"><a class="navItem" href="/boolean-operators">Boolean Operators</a></li><li class="navListItem"><a class="navItem" href="/other-operators">Other Operators</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Function Library</h3><ul class=""><li class="navListItem"><a class="navItem" href="/string-functions">String Functions</a></li><li class="navListItem navListItemActive"><a class="navItem" href="/numeric-functions">Numeric Functions</a></li><li class="navListItem"><a class="navItem" href="/aggregation-functions">Aggregation Functions</a></li><li class="navListItem"><a class="navItem" href="/boolean-functions">Boolean Functions</a></li><li class="navListItem"><a class="navItem" href="/array-functions">Array Functions</a></li><li class="navListItem"><a class="navItem" href="/object-functions">Object Functions</a></li><li class="navListItem"><a class="navItem" href="/date-time-functions">Date/Time Functions</a></li><li class="navListItem"><a class="navItem" href="/higher-order-functions">Higher Order Functions</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Extending JSONata</h3><ul class=""><li class="navListItem"><a class="navItem" href="/embedding-extending">Embedding and Extending JSONata</a></li><li class="navListItem"><a class="navItem" href="/contributing">Community and Contributing</a></li></ul></div></div></section></div><script>
var coll = document.getElementsByClassName('collapsible');
var checkActiveCategory = true;
for (var i = 0; i < coll.length; i++) {
var links = coll[i].nextElementSibling.getElementsByTagName('*');
if (checkActiveCategory){
for (var j = 0; j < links.length; j++) {
if (links[j].classList.contains('navListItemActive')){
coll[i].nextElementSibling.classList.toggle('hide');
coll[i].childNodes[1].classList.toggle('rotate');
checkActiveCategory = false;
break;
}
}
}
coll[i].addEventListener('click', function() {
var arrow = this.childNodes[1];
arrow.classList.toggle('rotate');
var content = this.nextElementSibling;
content.classList.toggle('hide');
});
}
document.addEventListener('DOMContentLoaded', function() {
createToggler('#navToggler', '#docsNav', 'docsSliderActive');
createToggler('#tocToggler', 'body', 'tocActive');
var headings = document.querySelector('.toc-headings');
headings && headings.addEventListener('click', function(event) {
var el = event.target;
while(el !== headings){
if (el.tagName === 'A') {
document.body.classList.remove('tocActive');
break;
} else{
el = el.parentNode;
}
}
}, false);
function createToggler(togglerSelector, targetSelector, className) {
var toggler = document.querySelector(togglerSelector);
var target = document.querySelector(targetSelector);
if (!toggler) {
return;
}
toggler.onclick = function(event) {
event.preventDefault();
target.classList.toggle(className);
};
}
});
</script></nav></div><div class="container mainContainer docsContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/jsonata-js/jsonata/edit/master/docs/numeric-functions.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 id="__docusaurus" class="postHeaderTitle">Numeric functions</h1></header><article><div><span><h2><a class="anchor" aria-hidden="true" id="number"></a><a href="#number" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$number()</code></h2>
<p><strong>Signature:</strong> <code>$number(arg)</code></p>
<p>Casts the <code>arg</code> parameter to a number using the following casting rules</p>
<ul>
<li>Numbers are unchanged</li>
<li>Strings that contain a sequence of characters that represent a legal JSON number are converted to that number</li>
<li>Hexadecimal numbers start with <code>0x</code>, Octal numbers with <code>0o</code>, binary numbers with <code>0b</code></li>
<li>Boolean <code>true</code> casts to <code>1</code>, Boolean <code>false</code> casts to <code>0</code></li>
<li>All other values cause an error to be thrown.</li>
</ul>
<p>If <code>arg</code> is not specified (i.e. this function is invoked with no arguments), then the context value is used as the value of <code>arg</code>.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$number("5")</code> => <code>5</code></li>
<li><code>$number("0x12")</code> => <code>0x18</code></li>
<li><code>["1", "2", "3", "4", "5"].$number()</code> => <code>[1, 2, 3, 4, 5]</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="abs"></a><a href="#abs" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$abs()</code></h2>
<p><strong>Signature:</strong> <code>$abs(number)</code></p>
<p>Returns the absolute value of the <code>number</code> parameter, i.e. if the number is negative, it returns the positive value.</p>
<p>If <code>number</code> is not specified (i.e. this function is invoked with no arguments), then the context value is used as the value of <code>number</code>.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$abs(5)</code> => <code>5</code></li>
<li><code>$abs(-5)</code> => <code>5</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="floor"></a><a href="#floor" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$floor()</code></h2>
<p><strong>Signature:</strong> <code>$floor(number)</code></p>
<p>Returns the value of <code>number</code> rounded down to the nearest integer that is smaller or equal to <code>number</code>.</p>
<p>If <code>number</code> is not specified (i.e. this function is invoked with no arguments), then the context value is used as the value of <code>number</code>.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$floor(5)</code> => <code>5</code></li>
<li><code>$floor(5.3)</code> => <code>5</code></li>
<li><code>$floor(5.8)</code> => <code>5</code></li>
<li><code>$floor(-5.3)</code> => <code>-6</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="ceil"></a><a href="#ceil" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$ceil()</code></h2>
<p><strong>Signature:</strong> <code>$ceil(number)</code></p>
<p>Returns the value of <code>number</code> rounded up to the nearest integer that is greater than or equal to <code>number</code>.</p>
<p>If <code>number</code> is not specified (i.e. this function is invoked with no arguments), then the context value is used as the value of <code>number</code>.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$ceil(5)</code> => <code>5</code></li>
<li><code>$ceil(5.3)</code> => <code>6</code></li>
<li><code>$ceil(5.8)</code> => <code>6</code></li>
<li><code>$ceil(-5.3)</code> => <code>-5</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="round"></a><a href="#round" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$round()</code></h2>
<p><strong>Signature:</strong> <code>$round(number [, precision])</code></p>
<p>Returns the value of the <code>number</code> parameter rounded to the number of decimal places specified by the optional <code>precision</code> parameter.</p>
<p>The <code>precision</code> parameter (which must be an integer) species the number of decimal places to be present in the rounded number. If <code>precision</code> is not specified then it defaults to the value <code>0</code> and the number is rounded to the nearest integer. If <code>precision</code> is negative, then its value specifies which column to round to on the left side of the decimal place</p>
<p>This function uses the <a href="https://en.wikipedia.org/wiki/Rounding#Round_half_to_even">Round half to even</a> strategy to decide which way to round numbers that fall exactly between two candidates at the specified precision. This strategy is commonly used in financial calculations and is the default rounding mode in IEEE 754.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$round(123.456)</code> => <code>123</code></li>
<li><code>$round(123.456, 2)</code> => <code>123.46</code></li>
<li><code>$round(123.456, -1)</code> => <code>120</code></li>
<li><code>$round(123.456, -2)</code> => <code>100</code></li>
<li><code>$round(11.5)</code> => <code>12</code></li>
<li><code>$round(12.5)</code> => <code>12</code></li>
<li><code>$round(125, -1)</code> => <code>120</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="power"></a><a href="#power" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$power()</code></h2>
<p><strong>Signature:</strong> <code>$power(base, exponent)</code></p>
<p>Returns the value of <code>base</code> raised to the power of <code>exponent</code> (<code>base<sup>exponent</sup></code>).</p>
<p>If <code>base</code> is not specified (i.e. this function is invoked with one argument), then the context value is used as the value of <code>base</code>.</p>
<p>An error is thrown if the values of <code>base</code> and <code>exponent</code> lead to a value that cannot be represented as a JSON number (e.g. Infinity, complex numbers).</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$power(2, 8)</code> => <code>256</code></li>
<li><code>$power(2, 0.5)</code> => <code>1.414213562373</code></li>
<li><code>$power(2, -2)</code> => <code>0.25</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="sqrt"></a><a href="#sqrt" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$sqrt()</code></h2>
<p><strong>Signature:</strong> <code>$sqrt(number)</code></p>
<p>Returns the square root of the value of the <code>number</code> parameter.</p>
<p>If <code>number</code> is not specified (i.e. this function is invoked with one argument), then the context value is used as the value of <code>number</code>.</p>
<p>An error is thrown if the value of <code>number</code> is negative.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$sqrt(4)</code> => <code>2</code></li>
<li><code>$sqrt(2)</code> => <code>1.414213562373</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="random"></a><a href="#random" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$random()</code></h2>
<p><strong>Signature:</strong> <code>$random()</code></p>
<p>Returns a pseudo random number greater than or equal to zero and less than one (<code>0 ≤ n < 1</code>)</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$random()</code> => <code>0.7973541067127</code></li>
<li><code>$random()</code> => <code>0.4029142127028</code></li>
<li><code>$random()</code> => <code>0.6558078550072</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="formatnumber"></a><a href="#formatnumber" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$formatNumber()</code></h2>
<p><strong>Signature:</strong> <code>$formatNumber(number, picture [, options])</code></p>
<p>Casts the <code>number</code> to a string and formats it to a decimal representation as specified by the <code>picture</code> string.</p>
<p>The behaviour of this function is consistent with the XPath/XQuery function <a href="https://www.w3.org/TR/xpath-functions-31/#func-format-number">fn:format-number</a> as defined in the XPath F&O 3.1 specification. The picture string parameter defines how the number is formatted and has the <a href="https://www.w3.org/TR/xpath-functions-31/#syntax-of-picture-string">same syntax</a> as fn:format-number.</p>
<p>The optional third argument <code>options</code> is used to override the default locale specific formatting characters such as the decimal separator. If supplied, this argument must be an object containing name/value pairs specified in the <a href="https://www.w3.org/TR/xpath-functions-31/#defining-decimal-format">decimal format</a> section of the XPath F&O 3.1 specification.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$formatNumber(12345.6, '#,###.00')</code> => <code>"12,345.60"</code></li>
<li><code>$formatNumber(1234.5678, "00.000e0")</code> => <code>"12.346e2"</code></li>
<li><code>$formatNumber(34.555, "#0.00;(#0.00)")</code> => <code>"34.56"</code></li>
<li><code>$formatNumber(-34.555, "#0.00;(#0.00)")</code> => <code>"(34.56)"</code></li>
<li><code>$formatNumber(0.14, "01%")</code> => <code>"14%"</code></li>
<li><code>$formatNumber(0.14, "###pm", {"per-mille": "pm"})</code> => <code>"140pm"</code></li>
<li><code>$formatNumber(1234.5678, "①①.①①①e①", {"zero-digit": "\u245f"})</code> => <code>"①②.③④⑥e②"</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="formatbase"></a><a href="#formatbase" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$formatBase()</code></h2>
<p><strong>Signature:</strong> <code>$formatBase(number [, radix])</code></p>
<p>Casts the <code>number</code> to a string and formats it to an integer represented in the number base specified by the <code>radix</code> argument. If <code>radix</code> is not specified, then it defaults to base 10. <code>radix</code> can be between 2 and 36, otherwise an error is thrown.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$formatBase(100, 2)</code> => <code>"1100100"</code></li>
<li><code>$formatBase(2555, 16)</code> => <code>"9fb"</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="formatinteger"></a><a href="#formatinteger" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$formatInteger()</code></h2>
<p><strong>Signature:</strong> <code>$formatInteger(number, picture)</code></p>
<p>Casts the <code>number</code> to a string and formats it to an integer representation as specified by the <code>picture</code> string.</p>
<p>The behaviour of this function is consistent with the two-argument version of the XPath/XQuery function <a href="https://www.w3.org/TR/xpath-functions-31/#func-format-integer">fn:format-integer</a> 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.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$formatInteger(2789, 'w')</code> => <code>"two thousand, seven hundred and eighty-nine"</code></li>
<li><code>$formatInteger(1999, 'I')</code> => <code>"MCMXCIX"</code></li>
</ul>
<h2><a class="anchor" aria-hidden="true" id="parseinteger"></a><a href="#parseinteger" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><code>$parseInteger()</code></h2>
<p><strong>Signature:</strong> <code>$parseInteger(string, picture)</code></p>
<p>Parses the contents of the <code>string</code> parameter to an integer (as a JSON number) using the format specified by the <code>picture</code> string.
The picture string parameter has the same format as <code>$formatInteger</code>. Although the XPath specification does not have an equivalent
function for parsing integers, this capability has been added to JSONata.</p>
<p><strong>Examples</strong></p>
<ul>
<li><code>$parseInteger("twelve thousand, four hundred and seventy-six", 'w')</code> => <code>12476</code></li>
<li><code>$parseInteger('12,345,678', '#,##0')</code> => <code>12345678</code></li>
</ul>
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/string-functions"><span class="arrow-prev">← </span><span>String Functions</span></a><a class="docs-next button" href="/aggregation-functions"><span>Aggregation Functions</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#number"><code>$number()</code></a></li><li><a href="#abs"><code>$abs()</code></a></li><li><a href="#floor"><code>$floor()</code></a></li><li><a href="#ceil"><code>$ceil()</code></a></li><li><a href="#round"><code>$round()</code></a></li><li><a href="#power"><code>$power()</code></a></li><li><a href="#sqrt"><code>$sqrt()</code></a></li><li><a href="#random"><code>$random()</code></a></li><li><a href="#formatnumber"><code>$formatNumber()</code></a></li><li><a href="#formatbase"><code>$formatBase()</code></a></li><li><a href="#formatinteger"><code>$formatInteger()</code></a></li><li><a href="#parseinteger"><code>$parseInteger()</code></a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/" class="nav-home"><img src="/img/jsonata-white-167.png" alt="JSONata"/></a><div><h5>JSONata</h5><a href="http://jsonata.org" target="_blank" rel="noreferrer noopener">JSON query and<br/>transformation language</a><a href="http://try.jsonata.org" target="_blank" rel="noreferrer noopener">Go play in the<br/>JSONata Exerciser</a></div><div><h5>Community</h5><a href="https://stackoverflow.com/questions/tagged/jsonata" target="_blank" rel="noreferrer noopener">Stack Overflow</a><a href="https://jsonata.slack.com/">Project Chat</a><a href="https://twitter.com/" target="_blank" rel="noreferrer noopener">Twitter</a></div><div><h5>More</h5><a href="https://github.com/jsonata-js/jsonata">GitHub</a><a class="github-button" href="https://github.com/jsonata-js/jsonata" data-icon="octicon-star" data-count-href="/jsonata-js/jsonata/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2021 JSONata.org</section></footer></div></body></html>