How to get specific currency symbol(rupee symbol in my case) in angular js instead of the default one (dollar $ symbol)

前端 未结 11 1446
野性不改
野性不改 2020-12-13 06:29

When i use \'currency\' in angular js, I am getting a dollar symbol. How to get required currency symbols based on the requirements. As if now i need to know how to display

相关标签:
11条回答
  • 2020-12-13 06:50

    According to Angular JS docs Link the currency can be changed

    Item Price<span style="font-weight:bold;">{{price | currency:[symbol]}}</span>
    Item Price in Dollar<span style="font-weight:bold;">{{price | currency:"USD$"}}</span>
    Item Price in Euro<span style="font-weight:bold;">{{price | currency:"&euro;"}}</span>
    

    And for INR it will be character code Link2

    Item Price in Ruppese<span style="font-weight:bold;">{{price | currency:"&#8377;"}}</span>
    

    "&#8377;" is the character code of :"₹"

    0 讨论(0)
  • 2020-12-13 06:51

    I'm late to the party but worked on this filter for my last project.

    if you have the ISO 4217 currency code (3 chars length e.g. USD, EUR, etc) isoCurrency can output the right format, fraction size and symbol.

    // in controller
    $scope.amount = 50.50;
    $scope.currency = 'USD';
    
    // in template
    {{ amount | isoCurrency:currency }} // $50.50
    
    • isoCurrency
    • Demo
    0 讨论(0)
  • 2020-12-13 06:52

    if you want to make it dynamic, here is my solution:

    HTML

    <div>{{ 100 | currencySymbol: 'USD' }}</div>
    

    Filter

    angular.filter('currencySymbol', function ($filter) {
        return function(amount, currency) {
            return $filter('currency')(amount, currency_symbols[currency]);
        }
    });
    

    Javascript currency array

    var currency_symbols = {
        'USD': '$', // US Dollar
        'EUR': '€', // Euro
        'GBP': '£', // British Pound Sterling
        'ILS': '₪', // Israeli New Sheqel
        'INR': '₹', // Indian Rupee
        'JPY': '¥', // Japanese Yen
        'KRW': '₩', // South Korean Won
        'NGN': '₦', // Nigerian Naira
        'PHP': '₱', // Philippine Peso
        'PLN': 'zł', // Polish Zloty
        'PYG': '₲', // Paraguayan Guarani
        'THB': '฿', // Thai Baht
        'UAH': '₴', // Ukrainian Hryvnia
        'VND': '₫', // Vietnamese Dong
    };
    
    0 讨论(0)
  • 2020-12-13 06:55

    Simple solution giving for the INR currency.

    If you want to display symbol

    Item Price<span style="font-weight:bold;">{{item.price | currency:'INR'}}</span>
    

    or

    Item Price<span style="font-weight:bold;">{{item.price | currency:'INR':'symbol'}}</span>
    

    or

    Item Price<span style="font-weight:bold;">{{item.price | currency:'INR':'symbol-narrow'}}</span>
    

    Result will look like: ₹140.00

    Or If you want to display code instead of symbol then use following

     Item Price<span style="font-weight:bold;">{{item.price | currency:'INR':'code'}}</span>
    

    Result will look like : INR140.00

    Similarly you can check for the code of the other countries and replace that instead of INR(India Code)

    0 讨论(0)
  • 2020-12-13 06:58
    <h2>{{8.99 | currency:'INR':true}}</h2>
    
    0 讨论(0)
  • 2020-12-13 07:00

    $ is the default symbol for angular currency filter. To get the result in other symbol, for example Rupee (₹), you must explicitly define it in your app. For displaying ₹ symbol you just have to add an option in currency.

    Example:

    <span> <b>{{i.price | currency : '&#8377;' }}</b> </span>

    &#8377; is the HTML code for ₹ symbol.

    0 讨论(0)
提交回复
热议问题