How do I display the rupee symbol in my java class?

if(this.currency.equalsIgnoreCase("₹")) {
    r="₹ "+r;
}

      

I want to compare

(Indian rupee symbol) in java. Here I am trying to print the ruble currency symbol, but it displays a type symbol instead â?¹

.

How to solve this problem?

+3


source to share


5 answers


You may try:

if(this.currency.equals("\u20B9")) {
    r="₹ "+r;
}

      

"\u20B9"

is the java encoding for the rupee character.



Additional Information:

+6


source


Your problem doesn’t seem to be that important for the comparison part of this snippet, but is mainly related to printing, to display that characters are correctly wrapped System.out

in OutputPrintWriter

with UTF-8 encoding, which is the configuration needed on some OSs:



OutputStreamWriter stdOut=new OutputStreamWriter(System.out,"UTF8");
stdOut.println("₹");

      

+2


source


    String string = "\u20B9";
    byte[] utf8 = string.getBytes("UTF-8");

    string = new String(utf8, "UTF-8");
    System.out.println(string);

      

+1


source


Try the following:

String s="₹";

if(s.equalsIgnoreCase("₹")) {
  System.out.println("if condition"+s);
}

      

0


source


  • Enable "UTF-8" in your editor (eclipse / netbean)
  • Or use unicode ("\ u20B9").
0


source







All Articles