1

How to convert currency HTML string into the symbol in JavaScript. Here is the response from the API. For example £ need to be converted like £.

You can check my API response here:

>   getOptions: {
>             "FKP": "Falkland Islands pound (£)",
>             "GBP": "Pound sterling (£)",
>             "GEL": "Georgian lari (ლ)",
>             "GGP": "Guernsey pound (£)",
>     }


Please suggest. 
https://html-online.com/editor/

Following this link if you are click this link (just paste inside in this link  `£` automatically converted pounds Symbol like £ )
Lavaraju
  • 2,614
  • 7
  • 29
  • 49
  • What exactly do you want to convert? One currency to another or currency code to currency symbol. – AsthaUndefined Aug 29 '17 at 05:19
  • still i have 56 Currency codes i want all are. Which i am using Currency code that it will be Displayed Symbol – Lavaraju Aug 29 '17 at 05:21
  • Check this https://stackoverflow.com/questions/19373860/convert-currency-names-to-currency-symbol – AsthaUndefined Aug 29 '17 at 05:22
  • 1
    Possible duplicate of [convert currency names to currency symbol](https://stackoverflow.com/questions/19373860/convert-currency-names-to-currency-symbol) – AsthaUndefined Aug 29 '17 at 05:22
  • Is this what you're looking for? http://graphemica.com/%C2%A3 – Sudheesh Singanamalla Aug 29 '17 at 05:28
  • But in this case in my Service response £ getting like this how can i convert this – Lavaraju Aug 29 '17 at 05:29
  • HTML Entity (Named) £ Convert to £ . Not only this one Entire Currency Codes Converting how it is possible – Lavaraju Aug 29 '17 at 05:31
  • You are not clear with your question. – AsthaUndefined Aug 29 '17 at 05:36
  • Please Check it once my Question , I modified Question – Lavaraju Aug 29 '17 at 05:39
  • There are many different currencies that use the same name, hence the common use of [*currency abbreviations*](https://en.wikipedia.org/wiki/ISO_4217) such as GBP, EGP, FKP, etc. Given £5.00, how does the viewer know which pound? – RobG Aug 29 '17 at 06:11
  • 1
    Possible duplicate of [Unescape HTML entities in Javascript?](https://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript) – Kaiido Aug 29 '17 at 06:23
  • @RobG he just wants to decode the html entity in the string he gets from his API. (e.g `getOptions["FKP"]`=>`"Falkland Islands pound (£)"`). Please [mjölnir this](https://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript). – Kaiido Aug 29 '17 at 06:25
  • @Lavaraju Your question is still unclear. Why do you need the symbol in JavaScript? Are you going to display it in HTML? – Buaban Aug 29 '17 at 07:35
  • @Buban Actually from Service response i am receiving `getOptions:{ "FKP": "Falkland Islands pound (£)" }` Now I want that String in As Currency Symbol like this £ – Lavaraju Aug 29 '17 at 10:40

4 Answers4

1

Yes, Finally I got a Absolute solution. like Just i installed npm install html-entities this. After that When we are using on Particular place like that Both two are giving this

const Entities = require('html-entities').AllHtmlEntities;

const entities = new Entities();

After that console.log(entities.decode('£')) getting result Output like £

Refer this link https://www.npmjs.com/package/html-entities

Lavaraju
  • 2,614
  • 7
  • 29
  • 49
  • If this is your answer, you should accept it so it can be referenced as a duplicate and also others know there's an accepted answer in search results. – RobG Aug 31 '17 at 00:51
0
var currency_symbol={
        "FKP": "¤",
        "GBP": "£",
        "GEL": "₡",
        "GGP": "₲",
},

Now get it by--
 currency_symbol.FKP
 currency_symbol.GBP etc
Kunvar Singh
  • 1,779
  • 2
  • 13
  • 21
  • but in my Service response like this bellow, var currency_symbol={ "GBP": "£", "GGP": "£", }, if i am ging currency_symbol.GBP displaying £ in to text not showing Currency Symbol – Lavaraju Aug 29 '17 at 06:08
  • Make sure that your document is in UTF-8, and for more info you can try it on w3school.com

    I will display £

    otherwise, i think you should customized your response.
    – Kunvar Singh Aug 29 '17 at 06:15
0

You are problably using the string in some kind of context that either escapes HTML control characters (such as &) or is not interpreted/displayed as HTML content, so the £ string will literally appear as such.

A workaround would be not to use HTML entities like £ but the actual Unicode characters for the various currency symbols:

getOptions: {
  "FKP": "Falkland Islands pound (\u00A3)",
  "GBP": "Pound sterling (\u00A3)",
  "GEL": "Georgian lari (\u10DA)",
  "GGP": "Guernsey pound (\u00A3)",
}

For your reference, see also this Unicode chart with other currency symbols.

RocketNuts
  • 9,958
  • 11
  • 47
  • 88
0

You can use Intl to format, use the locale and currency code to select the format.

var number = 123456.789;

// request a currency format
console.log(new Intl.NumberFormat('de-DE', {
  style: 'currency',
  currency: 'EUR'
}).format(number));
// → 123.456,79 €

// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', {
  style: 'currency',
  currency: 'JPY'
}).format(number));
// → ¥123,457

// limit to three significant digits
console.log(new Intl.NumberFormat('en-IN', {
  maximumSignificantDigits: 3
}).format(number));
// → 1,23,000

take a look here for more info

RobG
  • 142,382
  • 31
  • 172
  • 209
Ofer Skulsky
  • 685
  • 4
  • 10
  • Did you try it with FKP? – RobG Aug 29 '17 at 08:18
  • The list of currency codes includes it (i didn't test), you can find the list of codes here: https://www.currency-iso.org/dam/downloads/lists/list_one.xml – Ofer Skulsky Aug 30 '17 at 13:22
  • In all implementations I tested, using FKP returns the currency code (i.e. FKP), not the symbol (£), which is not what the OP wants. – RobG Aug 31 '17 at 00:50