1

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

Srinu
  • 141
  • 2
  • 2
  • 11
  • if your amount is in integer then you have to convert it into string before you can show the value like you want to because you have taken input type text here – Gaurav Srivastava Aug 08 '17 at 10:58

2 Answers2

4

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>
Vindhyachal Kumar
  • 1,713
  • 2
  • 23
  • 27
1

this seems like what you need

<input type="number" step="0.01" value="0.001"/>

Reference: input 2 decimal places

Naren Murali
  • 19,250
  • 3
  • 27
  • 54