ตัวกรอง number ของ AngularJS

คำหมายและวิธีใช้

number ตัวกรองจะจัดรูปแบบตัวเลขเป็นตัวอักษร.

หน้าที่เกี่ยวข้อง

AngularJS คู่มือฝึกฝน:Angular ฟิลเตอร์

ตัวอย่าง

ตัวอย่าง 1

จัดรูปแบบรางวัลเป็นตัวเลข:

<div ng-app="myApp" ng-controller="nCtrl">
<h1>{{prize | number}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('nCtrl', function($scope) {
    $scope.prize = 1000000;
});
</script>

ทดลองด้วยตัวเอง

ตัวอย่าง 2

แสดงน้ำหนักด้วยขาดเลขตัวเลขสามเท่า

<div ng-app="myApp" ng-controller="nCtrl">
<h1>{{weight | number : 3}} kg</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('nCtrl', function($scope) {
    $scope.weight = 9999;
});
</script>

ทดลองด้วยตัวเอง

ระบุราชน์

{{ string | number : fractionsize}}

ตัวแปร

ตัวแปร คำอธิบาย
fractionsize ตัวเลข กำหนดจำนวนที่แสดงหลังจุดของตัวเลข