Search code examples
javascriptunicodetitaniumappceleratorcurrency

Converting unicode to currency symbol in javascript


I am working with currency symbol in appcelerator for building apps in Android and iOS. I want make many parameters dynamic, so passing this value(u20b9) as api to app. Can't pass value(\u20b9) like this because of some reasons, so passing without slash.

When I use below code it works proper:-

var unicode = '\u20b9';
alert(unicode);

Output:- ₹

When I use below code:-

var unicode = '\\'+'u20b9';
alert(unicode);

Output:- \u20b9

Because of this, instead of ₹ it prints \u20b9 everywhere, which I don't want.

Thanks in advance.


Solution

  • The following works for me:

    console.log(String.fromCharCode(0x20aa)); // ₪ - Israeli Shekel
    console.log(String.fromCharCode(0x24)); // $ - US Dollar
    console.log(String.fromCharCode(0x20b9)); // ₹ - ???
    
    alert(String.fromCharCode(0x20aa) + "\n" + String.fromCharCode(0x24) + "\n" + String.fromCharCode(0x20b9));