• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

converting strings to money

Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
refering to the previous mails of subject "converting strings to money"

we have some fields like currency in our screen which stores currency as int/long data types at database level but at appliaction level,we are converting those int/long datatypes into strings as the currency is culture dependent data. For Example,different clients will use different operators(comma,Dot Operators)which gives different meaning for different cultures.

The following example will address the issue for a given Locale it will display the currency format. any comments for this?


//Parsing from string to double then formatting to currency basing on Locale.

import java.util.Locale;

import java.text.NumberFormat;

public class DemoCurrencyFormat{

public static void main(String args[])


NumberFormat numberFormat=NumberFormat.getInstance();


String str="1976.0826";

double d =Double.parseDouble(str);

// double userNumber=1976.0826;

numberFormat = NumberFormat.getCurrencyInstance(Locale.US);

System.out.println("User's Number(US):"+numberFormat.format(d));




User's Number(US):$1,976.08

Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check if this helps http://www.exampledepot.com/egs/java.text/Currency.html

Not an advanced question
[ September 13, 2007: Message edited by: Srikanth Basavaraju ]
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic