103

I am developing an application. And i need to set the symbol of Indian rupee on text view which is set with the text as amount.

Symbol:

enter image description here

I am having the font or .TTF file of this in Assets/fonts folder.

And i tried to use it as :

Typeface typeFace_Rupee = Typeface.createFromAsset(getAssets(),fonts/Rupee_Foradian.ttf");
TextView tvRupee = (TextView) findViewById(R.id.textview_rupee_mlsaa);
tvRupee.setTypeface(typeFace_Rupee);

// Tried to set symbol on text view as follows.
tvRupee.setText("`");

As above setting font i got null pointer error.

In word file after choosing font and typing ` we got the symbol. but it is not working in android.

So what steps should i follow to do this...

Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95
  • 9
    Simply use "\u20B9" in your settext string wherever you want to show symbol – Akbari Dipali Mar 02 '13 at 05:31
  • @Akbari Dipali I tried "\u20B9" but it shows box in text after running on emulator. But at layout design in GUI it looks fine. – Manoj Fegde Mar 02 '13 at 05:58
  • @Akbari Dipali Thank you. It is not working on Emulator but i tested it on device. An it works fine on that. – Manoj Fegde Mar 02 '13 at 06:10
  • @AkbariDipali I am trying to set above unicode in text view,it works well in upper version but in lower versions below 4.0 it is shows a box instead of symbol. Can you please help. how to set in all versions – Dory Apr 19 '13 at 07:55
  • @Nidhi Yes i got the same problem. It look as box on emulator but on device it runs fine for me. If you face problem then let me know. And if you got answer then upvote and me. – Manoj Fegde Apr 19 '13 at 08:27
  • @ManojFegde Actually on device of lower version I am having the same problem it shows me box instead of symbol – Dory Apr 19 '13 at 09:41
  • try using https://gist.github.com/john1jan/a82912fb355771e565bea1720439c5dc . It prefixes rupee symbol and adds even give comma separated amount – John Jul 08 '16 at 07:02
  • Sahi hai ye ekdam correct – Jaimin Modi Sep 27 '18 at 13:38

12 Answers12

232

enter image description here

Hi use this in Strings

For print rupee symbol: <string name="Rs">\u20B9</string>

For print Rs text: <string name="rs">\u20A8</string>

Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
androidgeek
  • 3,440
  • 1
  • 15
  • 27
  • I tried "\u20B9" but it shows box in text after running on emulator. But at layout design in GUI it looks fine. – Manoj Fegde Mar 02 '13 at 05:58
  • Thank you. It is not working on Emulator but i tested it on device. An it works fine on that. – Manoj Fegde Mar 02 '13 at 06:10
  • 1
    In my device the first `\u20B9` gives the rupees symbol. The second `\u20A8` gives 'Rs' text. Anyway I got that thanks. +1 – Mahendran Sakkarai Nov 26 '15 at 17:57
  • Your answer is absolutely correct. There's no doubt. But, I would like to add a line of code to help newbies into Android App Development. To use this resource into your programming, you need to call this string resource through this line of code: `this.getContext().getResources().getString(R.string.Rs)`. – meDeepakJain Jul 05 '19 at 21:22
25

Use \u20B9 if you want to print the Rupee Symbol
and
Use \u20A8 if you want to print "Rs"

Vojtech Vrbka
  • 5,342
  • 6
  • 44
  • 63
Sanyam Jain
  • 2,925
  • 2
  • 23
  • 30
  • 2
    try using https://gist.github.com/john1jan/a82912fb355771e565bea1720439c5dc . It prefixes rupee symbol and adds even give comma separated amount – John Jul 08 '16 at 07:03
  • try this. // Some code here child: Text('\u20B9 ${tx.amount}') // some code here – Ashish Dadhich Oct 26 '20 at 08:11
13

use on Adapter

Viewholder.price.setText("Price: \u20B9"+dataAdapterOBJ.getPrice());
Karan Chunara
  • 518
  • 4
  • 15
  • 1
    While this code might technically answer the question you would probably help OP more if you explain why your code solves op's problem – milo526 Feb 12 '18 at 10:24
10

Try this, Instead of Rupee_Foradian.ttf use Rupee.ttf it will work. am getting currency symbol.

Typeface tf = Typeface.createFromAsset(getAssets(), "font/Rupee.ttf");
textView1.setTypeface(tf);
textView1.setText("`");
MuraliGanesan
  • 3,233
  • 2
  • 16
  • 22
5

You can simply press Alt + Ctrl + 4

thatguy
  • 21,059
  • 6
  • 30
  • 40
4

In 2022, to set number into Indian currency with currency symbol Example:

double rupee = list.getAmount();
String x = NumberFormat.getCurrencyInstance(new Locale("en","in")).format(rupee);

no need of any file etc, currency in Indian format that is comma after three digit from right with rupee symbol

tintin
  • 335
  • 2
  • 8
3

Copy-paste the Unicode to XML or Java and it works just fine. For more info on the Unicode refer http://www.fileformat.info/info/unicode/char/20b9/index.htm

Rahul
  • 3,293
  • 2
  • 31
  • 43
Bala Vishnu
  • 2,588
  • 23
  • 20
2
 public static String getIndianRupee(String value) {
    Format format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
    return format.format(new BigDecimal(value));
}
Gautam Surani
  • 1,136
  • 10
  • 21
2

you can go with the below line of code for Flutter

child: Text('\u20B9 ${tx.amount}',
                        
Ashish Dadhich
  • 4,737
  • 4
  • 17
  • 25
1

Try this code snippet it's working fine in Xamarin.Forms

 CultureInfo india = new CultureInfo("hi-IN");

 var rupeeSymbol = india.NumberFormat.CurrencySymbol;
ADM
  • 20,406
  • 11
  • 52
  • 83
0

if you want to show Rupees Symbol using string.xml then define as

<string name="amount">\u20B9%,.2f Lakhs</string>

here .2f is for show only 2 decimal digit

set programatically

binding.txtView.text =resources.getString(R.string.amount, totalExp)

using DataBinding

android:text="@{@string/amount(model.amount)}"

it will show ₹xx.xx Lakhs modify as your need.

-1

Just simple write this code :

Text(
  '\u{20B9}${2880.0}',
  textAlign: TextAlign.start,
  style: TextStyle(
      color: const Color(0xFF000000),
      fontSize: 15.0,
      fontWeight: FontWeight.w300),
)
Hanisha
  • 849
  • 10
  • 8