• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

All I want is a � (pound) sign..

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to display the � sign on screen.

My code is:


I've looked up Literals and couldn't find it listed.

Is anyone able to help or alternatively point me in the right direction.

The output I am getting to screen is:


Balance: �135.64
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to do anything special. a printline of "�xyz" prints it.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Unicode value for the pound sign is \u00A3. In decimal, this is 163, which typically represents an accented "u" (�) in ascii extended. This is what you're seeing.

How these characters display depends on the environment. In my XP Command window, a println of "�xyz" displays �xyz. However, in Eclipse, this displays as �xyz. So although you're seeing � in the Command window, I expect that you would see � in a Java GUI.

Unfortunately, I don't know how to get the pound sign to display in the Command window. The extended ascii value for the pound sign is usually 156, so I expected char p = 156 to display as �, but it displays a question mark instead



ASCII: http://www.lookuptables.com/
Unicode: http://www.unicode.org/charts/PDF/U0080.pdf
[ February 26, 2005: Message edited by: marc weber ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On my terminal window 0xA3 gives me a £ sign
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn de Queiroz:
On my terminal window 0xA3 gives me a £ sign


Hmmm... What platform are you on, and how exactly are you coding this? I tried the following, but still get the accented u (in the Windows XP Command prompt):

char p = 0xA3; //decimal 163
System.out.println("0xA3: " + p);
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tried the following:



And still got the accented u on screen!
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Had a play with more extended codes. No luck though. My output resulted in the following with the relevant codes:

? This was 156
? This was 158
? This was 159
� This was 160
� This was 163
� This was 172
┤ This was 180
? This was 151
? This was 128

Can anyone see a pattern? Or help further?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The term "extended ascii" is pretty much useless nowadays. Do not trust anything or anyone which talks about "extended ascii" as if it means something. We're long past the point when ascii was enough, and there's more than one form of "extended ascii". You need to find out exactly what the default encoding is on your system - that's what your system speaks. Unfortunately Sun did not bother to create a simple method to do this, even though it's really useful information for you to have when debugging encoding problems. Try this:

I suspect that the encoding on your system will turn out to be one in which £ cannot be represented. Not all characters can be represented on all systems by default. Have you ever seen £ printed in a command window on your system? You may need to abandon System.out.println() and instead send your output to something that knows what a £ is. Good candidates for this would be a web browser (where you can represent £ as "£" - that's how I posted this) or some sort of JTextComponent (which understands Unicode much better than System.out does). Alternately, you may be able to reset your platform default encoding to something which supports £. Let us know what the default encoding is, and what kind of system you're on, and we may be able to help better.
[ February 27, 2005: Message edited by: Jim Yingst ]
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, many thanks for your response - much appreciated.

The operating system I am on is Windows 2000

I tried your suggestion and received the following error:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\maureen2>cd \

C:\>cd java

C:\java>cd bankaccount

C:\java\BankAccount>notepad Current.java

C:\java\BankAccount>javac TestClass.java
.\Current.java:138: cannot resolve symbol
symbol : class OutputStreamWriter
location: class Current
System.out.println(new OutputStreamWriter(new ByteArrayOutputStream()).getEncodi
ng());
^
.\Current.java:138: cannot resolve symbol
symbol : class ByteArrayOutputStream
location: class Current
System.out.println(new OutputStreamWriter(new ByteArrayOutputStream()).getEncodi
ng());
^
2 errors

C:\java\BankAccount>
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try putting an import statement at the top of your code, Maureen.

import java.io.*;

I can get a pound sign by typing alt-156, but not by typing alt-0156 and not (so far) by using System.out.println()
[ February 28, 2005: Message edited by: Marilyn de Queiroz ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't see £ in your Windows console, try changing the font of the window. Click the window's icon (left side of title bar), select Properties, and switch to Font tab. I use Lucida Console (I find it's the easiest on my eyes) and can see the £ when I type Alt-156.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
The term "extended ascii" is pretty much useless nowadays...


Yeah, that's why I qualified it with words like "typically" and "usually." I referenced extended acsii only because I think it explains why the accented u is appearing, but I didn't go down the path of different extended sets.

From a practical standpoint -- assuming we're stuck with a Windows console -- I suggest abandoning the symbol and using the acronym, "GBP."
[ February 28, 2005: Message edited by: marc weber ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic