Solved

Existing constant definitions for $, €, etc

Posted on 2012-04-04
5
235 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 68
Java: anonymous class 4 55
wild fly 8 startup error 2 82
Eclipse neon2 "Java build path" correctness 7 44
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

751 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