Solved

Decimal reducing

Posted on 2011-02-28
4
262 Views
Last Modified: 2012-05-11
I try to reduce decimals with formatter, but it's no result, it continue show all double decimals into text field.
 
formatter = new DecimalFormat("#0.0");

                resist = DCC.getInstance().getTextresistEURUSD();
                rt = Double.parseDouble(resist);

                drt = (rt - askPx) * 10000;
                formatter.format(drt);

                dresist = String.valueOf(drt);
                DCC.getInstance().setEURUSD_resist(dresist);

Open in new window

Logically everything OK.
1. I get string;
2. Convert it into double;
3. Make calculation;
4. Deduce decimals;
5. Convert back to string and publish.
Please advice.
0
Comment
Question by:gbcbr
  • 2
4 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
You should getbthe resulting string

StringBuffer s = formatter.format(drt);

String s1 = new String(s);

and then s1 would have less digits
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 62 total points
Comment Utility
You don't even need StringBuffer just
String s = formatter.format(drt);

This method does not change your double value - it just makes a string for you which is formatted
as you wish.
0
 
LVL 92

Accepted Solution

by:
objects earned 63 total points
Comment Utility
0
 

Author Comment

by:gbcbr
Comment Utility
Thank you for everybody
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now