UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

71 lines (60 loc) 2.09 kB
--- layout: page title: "JavaScript bcscale function" comments: true sharing: true footer: true alias: - /functions/view/bcscale:874 - /functions/view/bcscale - /functions/view/874 - /functions/bcscale:874 - /functions/874 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's bcscale {% codeblock bc/bcscale.js lang:js https://raw.github.com/kvz/phpjs/master/functions/bc/bcscale.js raw on github %} function bcscale (scale) { // From: http://phpjs.org/functions // + 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; } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/bc/bcscale.js) Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are the closest match to this hashtable-like data structure. Please also note that php.js offers community built functions and goes by the [McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just: - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/bc/bcscale.js) ### Example 1 This code {% codeblock lang:js example %} bcscale(1); {% endcodeblock %} Should return {% codeblock lang:js returns %} 3 {% endcodeblock %} ### Other PHP functions in the bc extension {% render_partial _includes/custom/bc.html %}