Solved

Decimal reducing

Posted on 2011-02-28
4
266 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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java 8 lambda expresssions exception handling 3 90
Maven Project: Hibernate Dependencies Conflict 10 22
map related example 6 48
by zero exception 10 41
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

773 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