Number to Fixed Decimal

Hi, i try to format my number with 2 digits.
The number yet shows so:
2,9280576811921426

In Javascript i can use toFixed(2), but in AngularJS its work and i can see it in the Console, but the input field in Chrome are empty :S

Here my Code:

$scope.$watch('celsius', function(value) {
   ......
   $scope.pressBar = pressBar.toFixed(2);
});

Hi,
can you share more details about the html code and the function? Maybe create a plunkr?

I tried the following and it worked without a problem:

HTML:

<label class="item item-input">
    <span class="input-label">Test</span>
    <input type="text" ng-model="test">
</label>

Controller

 var test = 2.9280576811921426;
 $scope.test = test.toFixed(2);

And the Result was the following:

So where is the variable pressBar defined? (Not $scope.pressBar).
And what does your HTML look like?

Edit: I found the Problem… I use . If i use “type=text” it works :smiley:

but its not sexy to use “text” type for a number filed

This is a general Angular JS Issue i think.

But you can use the following workaround:

$scope.pressBar = parseFloat("" + pressBar.toFixed(2));

I tested it and it will work.

1 Like

thxxxxx u are the best. It work :smiley: