468,727 Members | 1,665 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

number of decimals

Hey,

how can I set the number of decimals?

Example:
5 decimals 2.12345
2 decimals 2.12

I've found something about NumberFormat in the API, but without an example I
can't solve this...

Thanks in advance,
Oswald
Jul 17 '05 #1
3 5411
nfDollars = NumberFormat.getInstance();
nfDollars.setMaximumFractionDigits(2);
nfDollars.setMinimumFractionDigits(2);
double ss = 1.2323;
String s = nfDollars.format(ss).toString();

"Oswald" <fl*********@hotmail.com> wrote in message
news:3f***********************@reader2.news.skynet .be...
Hey,

how can I set the number of decimals?

Example:
5 decimals 2.12345
2 decimals 2.12

I've found something about NumberFormat in the API, but without an example I can't solve this...

Thanks in advance,
Oswald

Jul 17 '05 #2
I had to wait till i got home to answer this one, didn't have my docs on me
at work.

This is what i used when i needed to format things a specific way

DecimalFormat money = new DecimalFormat("$###,###,###.00");

then when ever you need to format something just do

money.format(value);

i belive you need to import java.text.* for that one

hoped that helped
Nick


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #3
Thanks guys,

this really helped me out!
"Oswald" <fl*********@hotmail.com> wrote in message
news:3f***********************@reader2.news.skynet .be...
Hey,

how can I set the number of decimals?

Example:
5 decimals 2.12345
2 decimals 2.12

I've found something about NumberFormat in the API, but without an example I can't solve this...

Thanks in advance,
Oswald

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by SoLRaC | last post: by
9 posts views Thread by Johnny Lee | last post: by
6 posts views Thread by Donal McWeeney | last post: by
4 posts views Thread by Dimos | last post: by
4 posts views Thread by Chris Davoli | last post: by
1 post views Thread by CARIGAR | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.