Lakshmi Prasanna
Lakshmi Prasanna

Reputation: 343

How to display 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 currency rupee symbol, but instead it is displaying the symbol like â?¹.

How to overcome this problem?

Upvotes: 4

Views: 25984

Answers (7)

Gaganam Krishna
Gaganam Krishna

Reputation: 151

I had a scenario using the SpringBoot 3.3.1 version and JDK 17

Adding Usecase : double total = invoiceDataList.stream().mapToDouble(data -> data.getPrice().doubleValue()).sum();

Paragraph totalParagraph = new Paragraph("Total: ₹" + String.format("%.2f", total))
                    .setFont(customFont)
                    .setFontSize(18)
                    .setTextAlignment(TextAlignment.RIGHT)
                    .setMarginTop(20);
                    doc.add(totalParagraph);

I can see the Rupee symbol on PDF invoice Report

enter image description here

Upvotes: 0

Rehan Nizami
Rehan Nizami

Reputation: 1

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

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

Upvotes: -1

Vijay
Vijay

Reputation: 501

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

Upvotes: 0

Chandu D
Chandu D

Reputation: 501

Try this:

String s="₹";

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

Upvotes: 0

Chandu D
Chandu D

Reputation: 501

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

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

Upvotes: 2

uraimo
uraimo

Reputation: 19821

Your problem seems to be not much about the compare part of that snippet but mainly related to the printing, to display that characters correctly wrap System.out in an OutputPrintWriter with an UTF-8 encoding, it's needed on some OS configuration:

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

Upvotes: 3

CoderNeji
CoderNeji

Reputation: 2074

You can try with:

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

"\u20B9" is the java encoding for rupee symbol.

More info:

Upvotes: 8

Related Questions