Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Decimal reducing

Posted on 2011-02-28
4
Medium Priority
?
274 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

730 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