Sirish Kumar
Sirish Kumar

Reputation: 86

formatting on ng-model for the display but keeping the value as a float in controller

Amount : <input type="text" ng-model="amount" />

Within controller:

amount=1000.00

Is there a way where I could display the value in the textbox as

Amount : 1,000.00

and still keep the value in controller as currency/number so that i dont have to parse them into float whenever i need to do some operations.

Upvotes: 1

Views: 1035

Answers (1)

Deep
Deep

Reputation: 9794

use it in the view like this for amount formatting.

<input type="text"  ng-model="amount.toLocaleString('en-US', {style: 'currency', currency: 'USD', minimumFractionDigits: 2})"/>

Upvotes: 1

Related Questions