Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Decimal reducing

Posted on 2011-02-28
4
Medium Priority
?
276 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
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 248 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 252 total points
ID: 34995184
0
 

Author Comment

by:gbcbr
ID: 34995199
Thank you for everybody
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 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