zoukankan      html  css  js  c++  java
  • 用js来实现银行家算法

    Number.prototype.round = function (len) {
    var old = this;
    var a1 = Math.pow(10, len) * old;
    a1 = Math.round(a1);
    var oldstr = old.toString()
    var start = oldstr.indexOf(".");
    if (start > 0 && oldstr.split(".")[1].length == len + 1) {
    if (oldstr.substr(start + len + 1, 1) == 5) {
    var flagval = oldstr.substr(start + len, 1) - 0;
    if (flagval % 2 == 0) {
    a1 = a1 - 1;
    }
    }
    }
    var b1 = a1 / Math.pow(10, len);
    return b1;
    }
    Number.prototype.oldtoFixed = Number.prototype.toFixed;
    Number.prototype.toFixed = function (len) {
    var old = this;
    var oldstr = old.toString()
    var start = oldstr.indexOf(".");
    if (len == 2 && start > 0 && oldstr.split(".")[1].length == 3) {
    return this.round(len);
    }
    else {
    return this.oldtoFixed(len);
    }
    }

  • 相关阅读:
    MySQL操作表中的数据
    mysql查询语句进阶
    mysql基本查询语句
    mysql函数
    mysql约束
    操作MySQL表
    操作MySQL数据库
    mysql视图
    as2 播放停止音效
    as3 深复制
  • 原文地址:https://www.cnblogs.com/yzryc/p/6053435.html
Copyright © 2011-2022 走看看