JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app ng-controller="InputCtrl">
<input type="number" ng-model="mynum1" price><br>
<input type="number" step="0.01" ng-model="mynum2" price><br>
<input type="number" ng-model="mynum3"><br>
<input type="number" ng-model="mynum4"><br>
</div>
JavaScript
angular.module('price', []).directive('price', function(numberFilter) {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$formatters.unshift(function(modelValue) {
return numberFilter(modelValue, 2);
});
}
};
});
var InputCtrl = function($scope) {
$scope.mynum1 = 5;
$scope.mynum2 = 5.01;
$scope.mynum3 = '5';
$scope.mynum4 = '5.00';
};