Chorme Subtraction Floating point processing

Source: Internet
Author: User
Tags mul

In the process of simple 1-0.7 found that the results of Chorme to 0.30000000000000004, instant egg pain, the data can be used?! Then went to Baidu found a simple two number of subtraction, and then modified the next, in addition to Division can be more than the number of operations. That way 3 numbers are added without having to set an add function. Original URL: http://www.2cto.com/kf/201502/376763.htmlfunction Add () {    var e,arr=[0],result = 0;    for ( var i = 0; i < arguments.length; i++) {        Try {            Arr.push (Arguments[i].tostring (). Split (". ") [1].length);       } catch (f) {}   };    Arr.sort (function (A, B) {return (B-A)} );    E = Math.pow (ten, arr[0]);    for (var i = 0; i < arguments.length; i++) {        Try {            result + mul (arguments[i],e)        } catch (f ) {}   };    return result/e;}  function Sub () {    var e,arr=[0],result;    for (var i = 0; i < arguments.length; i++) {&nbs P       Try {        &NBSp   Arr.push (Arguments[i].tostring (). Split (".") [1].length);       } catch (f) {}   };    Arr.sort (function (A, B) {return (B-A)});     E = Math.pow (ten, arr[0]);    result = Mul (arguments[0],e);    for (var i = 1; i < arg Uments.length; i++) {        Try {            Result-= Mul (arguments[i],e)   &NBSP ;    } catch (f) {}   };    return result/e;}  function Mul () {    var result = 1,c = 0;    for (var i = 0; i < arguments.length; i++) {&nbs P       Try {            C + = Arguments[i].tostring (). Split (".") [1].length;       } catch (f) {}   };    for (var i = 0; i < arguments.length ; i++) {        result *= number (arguments[i].tostring (). Replace (".", ""));   };  &nbsp ; Result/= Math.pow (ten, C);    return result;}  function Div (A, b) {    var c, d, E = 0,        f = 0;    Try {        E = a.tostring (). Split (".") [1].length;   } catch (g) {}    try {        f = b.tostring (). Split (".") [1].length;   } catch (g) {}    return c = number (a.tostring (). Replace (".", "")), d = Number (B.tostri Ng (). Replace (".", ""), Mul (C/D, Math.pow (F-E));}

Chorme Subtraction Floating-point number processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.