Reputation: 343
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
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
Upvotes: 0
Reputation: 1
String string = "\u20B9";
byte[] utf8 = string.getBytes("UTF-8");
string = new String(utf8, "UTF-8");
System.out.println(string);
Upvotes: -1
Reputation: 501
Upvotes: 0
Reputation: 501
Try this:
String s="₹";
if(s.equalsIgnoreCase("₹")) {
System.out.println("if condition"+s);
}
Upvotes: 0
Reputation: 501
String string = "\u20B9";
byte[] utf8 = string.getBytes("UTF-8");
string = new String(utf8, "UTF-8");
System.out.println(string);
Upvotes: 2
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
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