2

I have a java project that builds a web page and I need to show ≈99%. I have tried a couple of things, and none of them seem to work. Any ideas what I'm doing wrong?

My project takes a template HTML file, reads it in with JSOUP, then replaces some numbers in the template and then writes that to a file.

Charcter.toString( (char) 257)
Character.toString("\u2248".toCharArray()[0])
Jsoup.parse("\u2248").text()
"&asymp" + "99%"
"≈" + "99%"

This is what I get back now.

<h3>≈99%</h3>

Previous posts

Community
  • 1
  • 1
Pumphouse
  • 2,013
  • 17
  • 26
  • The problem is with your page's encoding. You have to set it properly. How is the page served to the user? You have described it all the way to a file, but it needs to get to the browser. How does it get there? Or if this is the file itself, you are writing it with the wrong encoding. – RealSkeptic Jul 30 '15 at 19:36
  • Hmmm. I'm actually creating a intermediate API that serves a toString() that when written to a file will be a webpage. Maybe I missed something at the top that sets the encoding. – Pumphouse Jul 30 '15 at 19:43

2 Answers2

3

Try specifying the character set for the page as UTF-8 in the HTML header.

<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  &asymp;99%
 </body>
</html>
schtever
  • 3,210
  • 16
  • 25
1

You have got the correct codes. Simply using the HTML hex code:

&#x2248;

will give you the approx. symbol.

RealSkeptic
  • 33,993
  • 7
  • 53
  • 79
sharmaap
  • 66
  • 6