simple-squiggle

A restricted subset of Squiggle
Log | Files | Refs | README

round.md (1518B)


      1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
      2 
      3 # Function round
      4 
      5 Round a value towards the nearest integer.
      6 For matrices, the function is evaluated element wise.
      7 
      8 
      9 ## Syntax
     10 
     11 ```js
     12 math.round(x)
     13 math.round(x, n)
     14 ```
     15 
     16 ### Parameters
     17 
     18 Parameter | Type | Description
     19 --------- | ---- | -----------
     20 `x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Number to be rounded
     21 `n` | number &#124; BigNumber &#124; Array | Number of decimals Default value: 0.
     22 
     23 ### Returns
     24 
     25 Type | Description
     26 ---- | -----------
     27 number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Rounded value
     28 
     29 
     30 ### Throws
     31 
     32 Type | Description
     33 ---- | -----------
     34 
     35 
     36 ## Examples
     37 
     38 ```js
     39 math.round(3.22)             // returns number 3
     40 math.round(3.82)             // returns number 4
     41 math.round(-4.2)             // returns number -4
     42 math.round(-4.7)             // returns number -5
     43 math.round(3.22, 1)          // returns number 3.2
     44 math.round(3.88, 1)          // returns number 3.9
     45 math.round(-4.21, 1)         // returns number -4.2
     46 math.round(-4.71, 1)         // returns number -4.7
     47 math.round(math.pi, 3)       // returns number 3.142
     48 math.round(123.45678, 2)     // returns number 123.46
     49 
     50 const c = math.complex(3.2, -2.7)
     51 math.round(c)                // returns Complex 3 - 3i
     52 
     53 math.round([3.2, 3.8, -4.7]) // returns Array [3, 4, -5]
     54 ```
     55 
     56 
     57 ## See also
     58 
     59 [ceil](ceil.md),
     60 [fix](fix.md),
     61 [floor](floor.md)