473,395 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

right-justifying currency

I'm trying to output currency columns to the console in table format.
I need a class that allows me to format doubles to currency and have
the columns right-justified. I've come up with a ridiculously
convoluted way to use MessageFormat() to do this, but there's got to
be a better way.

Is there a class that's good for this? There has to be. (I'm just
learning my way around Java).

Thanks.
Dennis
Jul 17 '05 #1
2 4606
NumberFormat nf = NumberFormat.getCurrencyInstance();
nf.format(double);

will get you a double formatted to local currency

"Dennis" <ml***@yahoo.com> wrote in message
news:2f**************************@posting.google.c om...
I'm trying to output currency columns to the console in table format.
I need a class that allows me to format doubles to currency and have
the columns right-justified. I've come up with a ridiculously
convoluted way to use MessageFormat() to do this, but there's got to
be a better way.

Is there a class that's good for this? There has to be. (I'm just
learning my way around Java).

Thanks.
Dennis

Jul 17 '05 #2
Let's assume that Marty's code gets you a string, call it abc.
Then to right align the string in a column:

int padding = width - abc.length();
while (--padding >= 0) System.out.print(" ");
System.out.print(abc);

where width is the column width you are using.

"Marty" <ic*******@hotmail.com> wrote in message
news:Qi*******************@rwcrnsc51.ops.asp.att.n et...
NumberFormat nf = NumberFormat.getCurrencyInstance();
nf.format(double);

will get you a double formatted to local currency

"Dennis" <ml***@yahoo.com> wrote in message
news:2f**************************@posting.google.c om...
I'm trying to output currency columns to the console in table format.
I need a class that allows me to format doubles to currency and have
the columns right-justified. I've come up with a ridiculously
convoluted way to use MessageFormat() to do this, but there's got to
be a better way.

Is there a class that's good for this? There has to be. (I'm just
learning my way around Java).

Thanks.
Dennis


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bo Wisén | last post by:
Hi, A project in VB6 recently worked without any problems but now it's complaining when I try to use 'Right$'. In immediate mode, when I'm typing 'print left$("123456",2)' I get the correct...
12
by: Ted Mencini | last post by:
When I replaced older <IMG ALIGN=RIGHT ...> tags with a CSS definition <IMG class=right ...> xxx.css: IMG.right { BORDER: 0; align: right } I notice that the effect is NOT the same....
22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
2
by: Dr. Richard E. Hawkins | last post by:
I've googled around, and asked everyone I know, but I still can't find any reference to anyone else having faced this particular IE bug with floats. I've put a page at...
22
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
3
by: deanfamily11 | last post by:
Ok, here's another problem I'm having. I've tried several different things, but I just can't get anything to be right justified. Any thoughts? #include <iostream> #include <iomanip>...
19
by: ashkaan57 | last post by:
Hi, I have a page in a right-to-left language and I am trying to make some bulleted lists using <ul>, but it puts the bullets to the left. Is there any way I can set the bullets to be on the...
5
by: tshad | last post by:
I have a datagrid that I cannot get to right justify a money amount (which is just a label). No matter what I do - it still right justifies it. <asp:TemplateColumn Visible="true"...
12
by: Dio1080 | last post by:
Ok, I need help on a for loop nested program using for loops, I'm trying to use a patten that goes like this: 123456 12345 1234 123 12 1 but when I try it, it goes like this: 123456
3
by: happyse27 | last post by:
Hi All, I wanted to align the text box for user registration but the code just wont budge... Kindly advise what is wrong? Cheers... Andrew <HTML>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.