Solved

Decimal reducing

Posted on 2011-02-28
4
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 34995157
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
ID: 34995178
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
ID: 34995184
0
 

Author Comment

by:gbcbr
ID: 34995199
Thank you for everybody
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

623 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