UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.

52 lines (35 loc) 1.2 kB
# Function boolean 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. ## Syntax ```js math.boolean(x) ``` ### Parameters Parameter | Type | Description --------- | ---- | ----------- `value` | String &#124; Number &#124; Boolean &#124; Array &#124; Matrix &#124; null | A value of any type ### Returns Type | Description ---- | ----------- Boolean &#124; Array &#124; Matrix | The boolean value ## Examples ```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] ``` ## See also [bignumber](bignumber.md), [complex](complex.md), [index](index.md), [matrix](matrix.md), [string](string.md), [unit](unit.md) <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->