1

Given this:

        <span ng-repeat="extra in extras">
            <br>
            <input type="checkbox" ng-click="addExtra()"  value="{{extra.id}}" >{{extra.name}} - <strong>{{extra.real_price}}</strong>
        </span>

How do i make the {{extra.real_price}} to output only numbers using filters ?

Example: extra.real_price being 'from 400€' to transform to '400'

1 Answer 1

2

you can use a regexp to strip out all characters except numeric ones:

app.filter('onlyNumbers', function () {
    return function (item) {
      return item.replace(/[^\d|^,|^.]/g, '');
    }
  });

The regexp can be read: replace all characters not being a number, nor a comma nor a point.

Note that, as you are using currency values, both point and comma should be accepted values.

These are some examples of usage and output:

{{ '23345€' | onlyNumbers }}       => 23345
{{ '$23345' | onlyNumbers }}       => 23345
{{ '$23345.00' | onlyNumbers }}    => 23345.00
{{ '23345,00 €' | onlyNumbers }}   => 23345,00
Sign up to request clarification or add additional context in comments.

1 Comment

Was this answer all right? Please consider accepting it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.