floating point numbers need to be formatted and displayed in grid. eg 123,456,567.82. Data from backend is 123456567.82. How can this be formatted in ag grid and have other features like sorting, filter work too. i did find a link in stack overflow to use Math. floor (num). tostring and applying some regex, but that truncates decimal points and not sortable.
2 Answers
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="costCtrl">
<p>Price = {{ price | currency }}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('costCtrl', function($scope) {
$scope.price = 123456567.82;
});
</script>
<p>The currency filter formats a number to a currency format.</p>
</body>
</html>
You can use currency filter for and look example may hope it will helps you
Comments
CellRendererUSD(params: any) {
var inrFormat = new Intl.NumberFormat('en-US', {
minimumFractionDigits: 2
});
return inrFormat.format(params.value);
}
columnDefs = [
{ headerName: 'A/c No', field: 'accountNo', width: 100 },
{ headerName: 'A/c Name', field: 'accountName' },
{ headerName: 'NAV', field: 'nav', cellRenderer: this.CellRendererUSD }
];
rowData = [
{ accountNo: '4', accountName: 'Janhavee', nav: 10000.49 },
{ accountNo: '5', accountName: 'Vignesh', nav: 100000.50 },
{ accountNo: '6', accountName: 'Upesh', nav: 1000000.51 }
];
1 Comment
Giulio Caccin
Can you please add some explanation to make easier for everyone to understand your answer?
