How to show truncated number in ng-value

130 views Asked by At

Let's assume that in my controller I have the following variable.

$scope.power = 16.345865;

In the html file I would like users to be able to modify (if they wish) the value of that variable. I want therefore use the following input.

<input type="number" ng-model="power" ng-value="power">

The problem is that this way all the decimal places will be shown, while I would happy that only the first two are.

In practice, instead of seeing 16.345865, the user would see only 16.35. Ideally, while the value showed is 16.35, the value in the variable (if not modified by the user) would stay 16.345865.

I thought this could be achieved by having something like this:

<input type="number" ng-model="power" ng-value="power | number : 2">

Unfortunately this seems not to work. How can I do it?

0

There are 0 answers