2019年12月17日 星期二

格式化為金額字串且去除結尾多餘小數

$scope.不含結尾多餘小數金額 = function (value, 小數位) {
       var s = $filter('currency')(value, '', 小數位);
        if (s.indexOf('.') > 0 && s.right(1) == '0') s = trim(trim(s, '0'), '.');
        return s;
    }

function trim(s, c) {
    if (c === "]") c = "\\]";
    if (c === "\\") c = "\\\\";
    return s.replace(new RegExp(
        "^[" + c + "]+|[" + c + "]+$", "g"
    ), "");
}

String.prototype.right = function (num) {
    return this.substring(this.length - num, this.length);
}

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...