Solved

Existing constant definitions for $, €, etc

Posted on 2012-04-04
5
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

623 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