I have a which has a default value declared in the controller and passed 'val:1.81' by ng-model. Such input must be numeric (type: number). By angular filters, managed to print only two decimal places on the next line by the filter 'number 2'. In addition, I need to include a couple of buttons to add or subtract '0.01' like a counter value input.
Is there any way to filter the input also with only two decimals? I mention this because as I sum by clicking the button, there comes a time that the input print eg '1.8800000000000001'.
var app = angular.module('myApp', []);
app.controller("mainCtrl", function($scope)
{
$scope.val = 1.80;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<div ng-app="myApp" ng-controller="mainCtrl">
<br/><br/>
<div>
<span style="color: red">Val input:</span>
<input type="number" ng-model="val"/>
<button ng-click="val = val - 0.01">-0.01</button>
<button ng-click="val = val + 0.01">+0.01</button>
</div>
<div>Val: {{val | number:2}}</div>
<hr>
Val2 (val + 20): {{ val2 = val + 20 | number:2 }}
<hr>
Val2 input:
<input type="number" ng-model="val2"/>
</div>