Results 1 to 1 of 1
Jan 13, 2012, 16:25 #1
- Join Date
- Jan 2008
- Knoxville TN
- 56 Post(s)
- 0 Thread(s)
About a month ago Microsoft published this up on the IEBlog
alert( Math.bc.div( 1, 3, 2) ); would return ".33", not ".3333333333333333333" or the like. BC Math is a library within Linux and PHP has a direct mapping inbuilt. It should be trivial for Firefox to build it in. My suggested API is as follows, and mimics the existing API seen in PHP, but isn't the exactly the same.
So far this object works like PHP library. That will be useful, but we can do better in js. All these functions can be called statically. However, I suggest allow bc object to be created with the new operator, taking one argument to be the starting value of the object (if no argument is supplied, it starts at 0 ). Such an object can then be chained, always passing itself as the starting value and returning itself for chaining. However, it would have a toString method to give it's current value, and a set() function would be added to set a new value for the object. The scale of an active object would be independent of the default scaling. This would allow the following.
var myMoney = new Math.bc().setScale(2); myMoney.add('2.33').add(1.15).sub(3).mul(2.5);