×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

output the £ sign

output the £ sign

output the £ sign

(OP)
How do i output the British pound sign to the standard output. when i try i get a u with a mark ontop of it. does any one know why this is? thanks

RE: output the £ sign

I to have exactly the same problem the only way i have found around it is to do the following...

import java.io.*; //Need this..

public class poundSign{
  public static void main(String[] arg){
    try {
     OutputStreamWriter osw = new OutputStreamWriter     
                                 (System.out, "Cp850");
     PrintWriter out = new PrintWriter (osw);

     System.out.println("£"); //prints out a funny sign

     out.print ("£"); //£ is displayed
     out.flush ();
    }
    catch (Exception e) {
     System.out.println (" pounds");
    }
  }
}

Hope this helps you. There may be another way of doing it but this is the only way i have found so far.

RE: output the £ sign

(OP)
thanks for sharing that. If any body knows of another way or why this is would you please let me know.

RE: output the £ sign

Caveat:  I am assuming that you are using a Windows/DOS system, so YMMV.

From the PrintStream javadoc:  All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. (Emphasis mine)

By default, all DOS consoles use MS-DOS Codepage 437 (US) as the default character encoding.

If you change this to Microsoft Windows Codepage 1252 (ANSI) using the "chcp" command (e.g., "c:\> chcp 1252"), you'll get the desired output from:

public class PoundSign{
    public static void main(String[] pArgs) {
        char thisChar = 0xA3;
        System.out.println(thisChar);
    }
}

HTH.

Chris Ciulla

RE: output the £ sign

(OP)
thanks thats much clearer, i will give that a try

RE: output the £ sign

Try this assignment:

class PoundSign
{
    public static void main(String [] args)
    {
        final char POUNDSIGN = 339;                // set a constant to hold a pound character

        System.out.println(POUNDSIGN + "50\n\n\n");            // does it work? Try it here.
    }
}


// arthurp

RE: output the £ sign

(OP)
thanks that worked and was simple.

RE: output the £ sign

Here are two more options:

Writer w = new OutputStreamWriter( System.out, "Cp437" );
PrintWriter out = new PrintWriter (w);
out.println("Pound sign: \u00a3");
out.flush();


Alternatively you can define the encoding on the java command line.

java -Dfile.encoding=cp437 MyJavaProgram

MyProgram.java
...
System.out.println("Pound sign: \u00a3");
...

Sean McEligot

RE: output the £ sign

(OP)
I apologise for not answering before now,  I have had some problems but no time to sort them. Anyhow thx for all your replies.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close