• 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

converting strings to money

 
Greenhorn
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?


//Example

//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();

numberFormat.setParseIntegerOnly(false);

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));

}

}





/*
Output:

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
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic