We help IT Professionals succeed at work.
Get Started

restrict decimal places for double datatype

Last Modified: 2017-03-13
I have java code that uses double type. I am using a sdk util function to round and restrict the decimal to 2 place. something like:
openCurrentBar=Util.round(localDataSeries.getOpen(paramInt), 2);
highCurrentBar=Util.round(localDataSeries.getHigh(paramInt), 2);
lowCurrentBar=Util.round(localDataSeries.getLow(paramInt), 2);

Open in new window

It does fix the issue temporarily but later in the code these variables show value of 11 digit decimal places again. This happens when they are used for calculation. How can I restrict the decimal paces permanently to 2 digits only such that no matter what happens in the code it does not show more than 2 digits. openCurrentBar should be something like 2365.21 and NOT 2365.213456721309.
Watch Question
Distinguished Expert 2020
This problem has been solved!
Unlock 2 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE