javascript - Angularjs avoid scientific notation for number filter -
i need print small numbers app. prefer if displayed in decimal format. there way angularjs number filter or have write own or modify existing 1 somehow?
http://jsfiddle.net/adukg/2386/
javascript
var myapp = angular.module('myapp',[]); function myctrl($scope) { $scope.mynum1 = 0.000001; $scope.mynum2 = 0.0000001; }
html
<div ng-controller="myctrl"> small number: {{mynum1 | number:8}}<br/> small number: {{mynum2 | number:8}} </div>
inconsistent output
small number: 0.00000100 small number: 1e-7
i haven't tested , i'm not sure how working on jsfiddle, seems working time being.
javascript
var app = angular.module('myapp', []); app.filter('decimalformat', function () { return function (text) { return parsefloat(text).tofixed(20).replace(/0+$/,''); }; });
html
<div ng-controller="myctrl"> small number: {{mynum1 | number:8 | decimalformat}}<br/> small number: {{mynum2 | number:8 | decimalformat}} </div>
edit after langdon's comment, added commas:
javascript
var app = angular.module('myapp', []); app.filter('decimal', function () { return function (text) { var parts = parsefloat(text).tofixed(8).split('.'); parts[0] = parts[0].replace(/\b(?=(\d{3})+(?!\d))/g, ','); return parts.join('.'); } }; }); function myctrl($scope) { $scope.mynum1 = 0.12345678912; $scope.mynum2 = 0.000000100001; $scope.mynum3 = 0; $scope.mynum3 = 1123123.05; }
html
<div ng-controller="myctrl"> small number: {{mynum1 | decimal}}<br/> small number: {{mynum2 | decimal}}<br/> zero: {{mynum3 | decimal}}<br/> million: {{mynum4 | decimal}}<br/> </div>
Comments
Post a Comment