am getting values from database as 10.00,520.00 but when am binding to input it showing as 10 and 520
example
<input type="text" ng-model="Amount">
$scope.Amount =10.00 ;
value binding to text box as 10 but i want bind 10.00
am getting values from database as 10.00,520.00 but when am binding to input it showing as 10 and 520
example
<input type="text" ng-model="Amount">
$scope.Amount =10.00 ;
value binding to text box as 10 but i want bind 10.00
Check the below working code.
var app = angular.module('plunker', []);
app.directive('validNumber', function () {
return {
link: function (scope, element, attrs, ngModelCtrl) {
setTimeout(function () {
var digits = element.val().split('.')[1];
digits = digits == null ? 2 : digits.length;
element.val(parseFloat(element.val()).toFixed(digits));
}, 100);
}
};
})
app.controller('MainCtrl', function ($scope) {
$scope.Amount = 10.0001;
});
<script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
<div ng-app="plunker" ng-controller="MainCtrl">
<input type="text" ng-model="Amount" valid-number />
{{Amount}}
</div>
this seems like what you need
<input type="number" step="0.01" value="0.001"/>
Reference: input 2 decimal places