Shivtek
asked on
Java formatter and decimal format
Hey Guys,
I am trying to print a variable:
DecimalFormat a = new DecimalFormat("###.00");
Formatter fmt = new Formatter();
System.out.printf("\tText $" + "\t\t" + a.format(totalText));
I want to put a formatter in it too so that the printed number right justifies.
Is there maybe a better way to do it.?
Thanks
I am trying to print a variable:
DecimalFormat a = new DecimalFormat("###.00");
Formatter fmt = new Formatter();
System.out.printf("\tText $" + "\t\t" + a.format(totalText));
I want to put a formatter in it too so that the printed number right justifies.
Is there maybe a better way to do it.?
Thanks
In the formatter class the output is right justified within the given width.
ASKER
how can I put a decimal format and formatter?
float pi = 3.1422313213;
System.out.format("%10.3f% n", pi); // --> " 3.142"
System.out.format("%10.3f%
I am still not clear about what output do you expect.
Here is a link on formatting - http://java.sun.com/docs/books/tutorial/java/data/numberformat.html
Here is a link on formatting - http://java.sun.com/docs/books/tutorial/java/data/numberformat.html
ASKER
I want to print:
exmaple:
Text $ 4523423.00
Link $ 656.98
Another $ 634.75
Something like this.
exmaple:
Text $ 4523423.00
Link $ 656.98
Another $ 634.75
Something like this.
Surely you'd probably need something more like this?
curr.png
curr.png
ASKER
Yes would need to text right justified as well...
And how do I do that?
And how do I do that?
>>Yes would need to text right justified as well...
The text is *left* justified ...
The text is *left* justified ...
ASKER
How is all this done?
Take a look at the following:
http://technojeeves.com/joomla/index.php/free/87-formatting-currency-in-java
http://technojeeves.com/joomla/index.php/free/87-formatting-currency-in-java
Doesn't look like you need a DecimalFormat at all, what a_b posted above looks list it is all you need
float pi = 3.1422313213;
System.out.format("%10.3f% n", pi); // --> " 3.142"
float pi = 3.1422313213;
System.out.format("%10.3f%
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What does the %n do?
new line
ASKER
GREAT!!! a_b, I must say your answer was THE BEST....WICKED *_*
Thanks a lot!!
Thanks a lot!!
>>I must say your answer was THE BEST
That gives the following, with the amount right-justified, but with the currency sign disassociated from the amount
Text $ 4523423.00
Link $ 656.98
Another $ 634.75
That gives the following, with the amount right-justified, but with the currency sign disassociated from the amount
Text $ 4523423.00
Link $ 656.98
Another $ 634.75