-2
Vector <Double> v=new Vector<Double>();

for (double d=1;d<=50;d++) {
    v.add(d);
    v.add((double)Math.round((d*1.3)*100/100));
}

System.out.println(Math.round((5.255685650*1.3)*100/100));
System.out.println("Multiples of 1.3 is -->"+v);

I want the decimal like 45.54 which is stored in vector also. Please tell me..

Il Vic
  • 5,576
  • 4
  • 26
  • 37
  • 2
    So what exactly is the problem? – Mureinik Jan 02 '16 at 17:07
  • what are you trying to do? – salmanwahed Jan 02 '16 at 17:07
  • 1
    Why are you using `Vector`? It's 2016, not 1996. – Kayaman Jan 02 '16 at 17:09
  • For your question to set 2 decimal points, it is already answered [here](http://stackoverflow.com/questions/14845937/java-how-to-set-precision-for-double-value)! – JinalG Jan 02 '16 at 17:29
  • You have your closing parenthesis in the wrong place. Try `Math.round((d*1.3)*100)/100` rather than `Math.round((d*1.3)*100/100)` – Mr Lister Jan 04 '16 at 21:29
  • i want to store a decimal number which is automatically generated by any mathematical operation or something else. for example 565.5660000000225 like this. so, I want to reduce the decimal points like 565.56 . Then it is stored in to a collection variables (any type of collection doesn't matter it is.) and displays it.. This is what i got problem while practising collections topic. – rajawin2008 Jan 06 '16 at 12:15

2 Answers2

0

For example if you have a number with five decimal places that you want to convert to two decimal places:

num=45.54345;
num*=100;  // multiply the number by 100 to get 4554.345
num = round(num); // round the number to 4554
num/=100;  // divide the number by 100 to get 45.54
Greg Marsh
  • 209
  • 1
  • 2
  • 9
0

Please Use the DecimalFormat class to format the double values. Please follow the link.

[https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html][1]

BValluri
  • 916
  • 1
  • 6
  • 10