Solved

Existing constant definitions for $, €, etc

Posted on 2012-04-04
5
233 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
ID: 37807443
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
ID: 37807472
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
ID: 37807515
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
ID: 37808610
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37813967
:)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 58
Custom Java Application connects to database: Which one of the 20? 4 35
Java string replace 11 54
going to wrong jsp page 2 33
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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