61 lines
1.7 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-boolean">Function boolean <a href="#function-boolean" title="Permalink">#</a></h1>
Create a boolean or convert a string or number to a boolean.
In case of a number, `true` is returned for non-zero numbers, and `false` in
case of zero.
Strings can be `'true'` or `'false'`, or can contain a number.
When value is a matrix, all elements will be converted to boolean.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.boolean(x)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`value` | string &#124; number &#124; boolean &#124; Array &#124; Matrix &#124; null | A value of any type
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
boolean &#124; Array &#124; Matrix | The boolean value
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
Type | Description
---- | -----------
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
math.boolean(0) // returns false
math.boolean(1) // returns true
math.boolean(-3) // returns true
math.boolean('true') // returns true
math.boolean('false') // returns false
math.boolean([1, 0, 1, 1]) // returns [true, false, true, true]
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[bignumber](bignumber.html),
[complex](complex.html),
[index](index.html),
[matrix](matrix.html),
[string](string.html),
[unit](unit.html)