formatting number

M

mank

I have to write a method which is supposed to do the following -

When input is 2.00, it converts to $2
When input is 2.01, it converts to $2.01
When input is 2, it converts to $2

Is there any utility method in java which can do that?
 
P

Paul Lutus

mank said:
I have to write a method which is supposed to do the following -

When input is 2.00, it converts to $2
When input is 2.01, it converts to $2.01
When input is 2, it converts to $2

Is there any utility method in java which can do that?

Yes, you can use class DecimalFormat to do it. Because this is very likely a
homework assignment, if you will post your code, someone here will help you
get it working.
 
A

Alex Hunsley

mank said:
I have to write a method which is supposed to do the following -

When input is 2.00, it converts to $2
When input is 2.01, it converts to $2.01
When input is 2, it converts to $2

Is there any utility method in java which can do that?

This question is much more suited to comp.lang.java.help.
As Paul said, post the code you have so far, and what it's doing wrong.
This newsgroup ain't a code generating machine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top