JavaScript bcscale
Sets default scale parameter for all bc math functions
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 2526 27 28 29 | function bcscale(scale) { // Sets default scale parameter for all bc math functions // // version: 909.322 // discuss at: http://phpjs.org/functions/bcscale // + original by: lmeyrick (https://sourceforge.net/projects/bcmath-js/)this. // - depends on: _phpjs_shared_bc // * example 1: bcscale(1); // * returns 1: 3 // @todo: implement these testcases// bcscale(0); // // bcmath.test.result('bcscale', 1, false, bcscale('fail')); // bcmath.test.result('bcscale', 2, false, bcscale(-1)); // bcmath.test.result('bcscale', 3, true, bcscale(5));// bcmath.test.result('bcscale', 4, true, bcscale(0)); var libbcmath = this._phpjs_shared_bc(); scale = parseInt(scale, 10); if (isNaN(scale)) { return false; } if (scale < 0) { return false; } libbcmath.scale = scale; return true; } |
Examples
Running
1 | bcscale(1); |
Should return
1 | 3 |
Dependencies
In order to use this function, you also need:
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have bcscale goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: Anonymous and Shawn Houser.
<your name here>