Results 1 to 5 of 5

Thread: java currency

  1. #1
    alfarida is offline Member
    Join Date
    Nov 2010
    Posts
    16
    Rep Power
    0

    Default java currency

    Hi

    I want to add a currency like $ to a double ammount in java swing.
    what method do use .

    thanks.

    Rida

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    This is not a Swing issue but rather a number format issue. Look into using a NumberFormat.getCurrencyInstance() to be able to format your doubles to a currency String.

  3. #3
    alfarida is offline Member
    Join Date
    Nov 2010
    Posts
    16
    Rep Power
    0

    Default java currency

    Hi Mate s

    thanks .i used this method

    int sum=1000;
    NumberFormat nf = NumberFormat.getInstance();
    Currency curr = Currency.getInstance(Locale.ITALY);
    System.out.println( sum + curr.getSymbol());

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    A word to the wise - floating point numerics should not be used for currency storage or calculation, as FP has problems with precision. Use integer numerics and store and calculate using the smallest currency unit (pence, cents, etc). If the amounts will be large, use BigDecimal or BigInteger. See Primitive Data Types (float & double), Beware Floating Point, etc.

Similar Threads

  1. Currency Converter Applet Help...
    By MarkL410 in forum Java Applets
    Replies: 3
    Last Post: 11-09-2010, 06:27 PM
  2. Currency Coverter Project
    By Ejava in forum New To Java
    Replies: 1
    Last Post: 04-29-2010, 08:02 PM
  3. Currency Converter!!!!
    By Pascal Nouma in forum AWT / Swing
    Replies: 2
    Last Post: 04-02-2009, 08:23 AM
  4. Formatting a number to currency
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-16-2008, 11:59 PM
  5. Setting currency
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-16-2007, 03:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •