Solved

Existing constant definitions for $, €, etc

Posted on 2012-04-04
5
230 Views
Last Modified: 2012-04-05
Are there existing constant definitions for symbols like $ and €?
such that I could refer to them like:
String myString = SomeClass.DOLLAR_SIGN + myDouble;

Open in new window

Either in Java proper, or another API like Apache Commons.
0
Comment
Question by:allelopath
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:HomerTNachoCheese
Comment Utility
Maybe all you need to do is something similar to this.  This is pseudocode, but you may be able to get what I mean here.


String myString = char(36) + myDouble;

String myString = char(128) + myDouble;

36 would be $
128 would be €

This function I put in is just something pulled from MS Office, but there probably is something similar in what you are programming with.

Are you able to just simply put "$" + myDouble in your code?
0
 
LVL 9

Expert Comment

by:Evan Cutler
Comment Utility
You can use an ENUM:

public enum CurrencyType {
    Pound, Dollar, Lyra, Sheckel }
public class EnumTest {
    Day day;
    
    public CurrType(Currency Type Money) {
        this.Money = Money;
    }
    
    public void MoneyIsFun() {
        switch (Money) {
            case Pound:
                System.out.println("<insert ASCII Symbol here>");
                break;
                    
            case Dollar:
                System.out.println("<insert ASCII Symbol here>");
                break;
                         
            case Lyra: case Sheckel :
                System.out.println("<insert ASCII Symbol here>");
                break;
                        
            default:
                System.out.println("<insert ASCII Symbol here>");
                break;
        }
    }
    
    public static void main(String[] args) {
        EnumTest firstCash = new CurrType(Money.Dollar);
        firstCash.MoneyIsFun();
        EnumTest thirdCash = new CurrType(Money.Pound);
        thirdCash.MoneyIsFun();
        EnumTest fifthCash = new CurrType(Money.Sheckel);
        fifthCash.MoneyIsFun();
        EnumTest sixthCash = new CurrType(Money.Lyra);
        sixthCash.MoneyIsFun();
    }
}

Open in new window


This way you can assign more stuff to it, and do more things.
Hope it helps.
0
 
LVL 9

Expert Comment

by:Evan Cutler
Comment Utility
Here's a link to what I'm talking about: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 68
changePi Challenge 15 75
endX challenge 2 48
PDFBox - convert image to PDF, PDF resolution 3 61
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now