my dog learned polymorphism
The moose likes Java in General and the fly likes converting strings to money Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "converting strings to money" Watch "converting strings to money" New topic

converting strings to money

Giri moh'kar

Joined: Jun 11, 2007
Posts: 7
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

Srikanth Basa
Ranch Hand

Joined: Jun 06, 2005
Posts: 241
Check if this helps

Not an advanced question
[ September 13, 2007: Message edited by: Srikanth Basavaraju ]
I agree. Here's the link:
subject: converting strings to money
jQuery in Action, 3rd edition