README.md (1843B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Round 22 23 > Round a numeric value to the nearest integer. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var round = require( '@stdlib/math/base/special/round' ); 31 ``` 32 33 #### round( x ) 34 35 Rounds a `numeric` value to the nearest `integer`. 36 37 ```javascript 38 var v = round( -4.2 ); 39 // returns -4.0 40 41 v = round( -4.5 ); 42 // returns -4.0 43 44 v = round( -4.6 ); 45 // returns -5.0 46 47 v = round( 9.99999 ); 48 // returns 10.0 49 50 v = round( 9.5 ); 51 // returns 10.0 52 53 v = round( 9.2 ); 54 // returns 9.0 55 56 v = round( 0.0 ); 57 // returns 0.0 58 59 v = round( -0.0 ); 60 // returns -0.0 61 62 v = round( Infinity ); 63 // returns Infinity 64 65 v = round( -Infinity ); 66 // returns -Infinity 67 68 v = round( NaN ); 69 // returns NaN 70 ``` 71 72 </section> 73 74 <!-- /.usage --> 75 76 <section class="notes"> 77 78 ## Notes 79 80 - Ties are rounded toward positive infinity. 81 82 </section> 83 84 <!-- /.notes --> 85 86 <section class="examples"> 87 88 ## Examples 89 90 <!-- eslint no-undef: "error" --> 91 92 ```javascript 93 var randu = require( '@stdlib/random/base/randu' ); 94 var round = require( '@stdlib/math/base/special/round' ); 95 96 var x; 97 var i; 98 99 for ( i = 0; i < 100; i++ ) { 100 x = (randu()*100.0) - 50.0; 101 console.log( 'Value: %d. Rounded: %d.', x, round( x ) ); 102 } 103 ``` 104 105 </section> 106 107 <!-- /.examples --> 108 109 <section class="links"> 110 111 </section> 112 113 <!-- /.links -->