• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

another question on arrays

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

if this is a given array:
Integer[] ir = {12, 45678, 90123, 3};

how do i rewrite this loop:



to get following output:
-----------------
12 (...e.g. Euro)
45.678
90.123
3
-----------------

i am trying to get the programme to print out numbers (without comma, or decimal separators : as seen in Array "ir" ) as currency sums...
....however: the sums should be formatted the way some european countries do...(i.e. not with commas as is done in the US for example - but with decimal points)...

what functions/methods etc do i need to append (to replace the " *** " )...

i would also appreciate somene explaining to me where (in the API ? ) i can get more help.....

i've looked through the classes: DecimalFormat and Formatter, as well as Locale..... but it's gotten me even more confused...

i'd appreciate some help.

thanx!

-W.O.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> what functions/methods etc do i need to append (to replace the " *** " )...

DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.GERMAN);
System.out.println(df.format(ir[i]));
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
***.getCurrencyInstance***
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Monk Fox", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, thanx a million Ajay / Monk....

looks like a workable solution, can anyone tell me how i would do it using "printf" ....as i was told it would be more efficient...(how true is this?) ....and are there any advantages of using "printf" over the way suggested by Ajay/ Monk ?

thanx in advance.

-W.O.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an exmple usinng printf(), although I have no idea about differences in efficiency
The flags & conversion syntax used in the printf() method are located in the documentation for the Formatter class. They are a little confusing as you undoubtedly have already seen. The most straightforward way IMO is using the DecimalFormat class as has already been suggested. But it can be done either way.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You use letters preceded by % characters in a String to represent an output. So
%d will print out a decimal integer calue of how mush money you should send me.
You can use different figures after the % to have the number take up a certain number of spaces, with or without leading 000 or +-.
%n is new line, and %6.2f is a fixed-point decimal number occupying six spaces, two after the decimal point (eg 123.45 takes up six spaces).
There are hundreds of different combinations available; look in the API spceification for the java.util.Formatter class.
[ April 17, 2006: Message edited by: Campbell Ritchie ]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lol printf is goofy, just use println or print...

C and C++ use printf....

Monk...
 
Wolfgang Obi
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx alot everyone,....

you've been a great help.....

-W.O.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic