Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:59:17+00:00 2026-06-15T08:59:17+00:00

I saw this solution http://jsfiddle.net/gronky/GnTDJ/ and it works. That is, when you input 25,

  • 0

I saw this solution http://jsfiddle.net/gronky/GnTDJ/ and it works. That is, when you input 25, it is pushed back to model as 0.25

HTML:

<script type="text/javascript" ng:autobind
        src="http://code.angularjs.org/0.9.17/angular-0.9.17.js"></script>
<script>
function Main() {
    this.var = '1.0000';
}
</script>
<div ng:controller="Main">
    <input type="text" name="var" ng:format="percent">
    <pre>var = {{var|json}}</pre>
</div>​

JavaScript:

angular.formatter('percent', {
  parse: function(value) {
    var m = value.match(/^(\d+)\/(\d+)/);
    if (m != null)
      return angular.filter.number(parseInt(m[1])/parseInt(m[2]), 2);
    return angular.filter.number(parseFloat(value)/100, 2);
  },
  format: function(value) {
    return angular.filter.number(parseFloat(value)*100, 0);
  },
});
​

I tried making it work on latest AngularJS, it doesn’t work anymore though http://jsfiddle.net/TrJcB/ That is, when you input 25, it is pushed back as 25 also, it doesn’t push the correct 0.25 value to model.

Or perhaps there’s already a built-in formatter for percent? I wanted currency formatter too, or comma separated number.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:59:19+00:00Added an answer on June 15, 2026 at 8:59 am

    The fiddle doesn’t work with current Angular version since quite a few APIs have changed since. angular.formatter is no longer available and neither is angular.filter.

    The way to write it now is to use a directive and make use of $parser and $formatter available on the directive controller. So your link function will look something like

    link: function(scope, ele, attr, ctrl){
            ctrl.$parsers.unshift(
                function(viewValue){
                    return $filter('number')(parseFloat(viewValue)/100, 2);
                }
            );
            ctrl.$formatters.unshift(
                function(modelValue){
                    return $filter('number')(parseFloat(modelValue)*100, 2);
                }
            );
          }
    

    Also the filters are now accessed through $filter service. You can find the documentation here: https://docs.angularjs.org/api/ng/filter/number

    Updated fiddle for the original example: http://jsfiddle.net/abhaga/DdeCZ/18/

    Currency filter is already available in angular: https://docs.angularjs.org/api/ng/filter/currency

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this: http://yukelzon.blogspot.com/2005/07/python-locks.html when looking for a solution to add some locking to
I saw in this post a solution that fits exactly my needs https://stackoverflow.com/a/8858815/1462911 .
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I saw this on a CMS(sitecore) based Asp.net 2.0 Webform based site. <a class=boardTextLink
I saw this HTML minifier in Ajaxian and it made me wonder if its
I was looking at the 14 days of jquery http://jquery14.com/day-01/jquery-14 and I saw this
I saw this thread but the solution is not what I'm looking for. I
I saw this question on a forum: http://www.geeksforgeeks.org/archives/19042 Given an undirected graph and a
I got a solution with main page ( Default.aspx) at this location D:\Websites\wwwFlofab\HomeSite\Default\Pages that
I saw this question here . The solution was to make a xml for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.