README.md (1796B)
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 # roundsd 22 23 > Round a numeric value to the nearest number with `n` significant figures. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var roundsd = require( '@stdlib/math/base/special/roundsd' ); 31 ``` 32 33 #### roundsd( x, n\[, b] ) 34 35 Rounds a `numeric` value to the nearest `number` with `n` significant figures. 36 37 ```javascript 38 var v = roundsd( 3.141592653589793, 3 ); 39 // returns 3.14 40 41 v = roundsd( 3.141592653589793, 1 ); 42 // returns 3.0 43 44 v = roundsd( 12368.0, 2 ); 45 // returns 12000.0 46 ``` 47 48 The default base is `10` (decimal). To round using a different base, provide a third argument. 49 50 ```javascript 51 var v = roundsd( 0.0313, 2, 2 ); 52 // returns 0.03125 53 ``` 54 55 </section> 56 57 <!-- /.usage --> 58 59 <section class="notes"> 60 61 </section> 62 63 <!-- /.notes --> 64 65 <section class="examples"> 66 67 ## Examples 68 69 <!-- eslint no-undef: "error" --> 70 71 ```javascript 72 var randu = require( '@stdlib/random/base/randu' ); 73 var roundsd = require( '@stdlib/math/base/special/roundsd' ); 74 75 var x; 76 var y; 77 var i; 78 79 for ( i = 0; i < 100; i++ ) { 80 x = (randu()*10000.0) - 5000.0; 81 y = roundsd( x, 5 ); 82 console.log( 'x: %d. Rounded: %d.', x, y ); 83 } 84 ``` 85 86 </section> 87 88 <!-- /.examples --> 89 90 <section class="links"> 91 92 </section> 93 94 <!-- /.links -->