angularjs - Number filter filters number down to two decimals, but does not display it that way -


this see:

the value set @ 160.90, displays 160.8999999999 etc.

<input class="form-control" ng-model="imprint.total"      value="{{imprint.total | number:2}}" readonly> 

it goes through filtering of inputs total, it's price multiplied quantity.

the value in value attribute overridden ng-model directive when sets viewvalue renders. have readonly textbox remove ng-model it.

<input class="form-control"         value="{{imprint.total | number:2}}" readonly> 

with ng-model , format live data entry need create directive , use parsers/formatters format value.

angular.module('app', []).directive('format', ['numberfilter',    function(numberfilter) {      return {        restrict: 'a',        require: 'ngmodel',        link: function(scope, elm, attr, ngmodel) {          var decplaces = attr.format || 2;            function formatter(value) {              if (value) {              return numberfilter(value, decplaces);            }          }            ngmodel.$formatters.push(formatter);          }      }    }  ]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div ng-app="app" ng-init="imprint=164.899999">    <input class="form-control" value="{{imprint | number:2}}" readonly>      <input class="form-control" ng-model="imprint" format="2" readonly>    </div>


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -