Hi
I have double values like this,

``````  double value1  = 100.0
double value2  = 100.23
``````

I need to convert like this,

``````  value1  = 100
value2  = 100.23
``````

Kindly give some sugesstions to convert like this.

4
Contributors
6
Replies
16
Views
4 Years
Discussion Span
Last Post by stultuske

ehm, seems to me you could use a DecimalFormat, that returns a String dependent on whether there are numbers after the decimal point or not.

simple typecasting from float to int might work though..

Venkatesh: no, it might not. did you see the .23 for the second number? good luck in getting that in an int.

Edited by stultuske

use System.out.printf , example:
double i = 5.3333;
System.out.printf("%.2f", i);
output: 5.33

M.Mahajna: you may want to re-read the original question. I think you didn't quite understood what he's looking for. his point is to only have decimals if there are decimal numbers.

M.Mahajna: you may want to re-read the original question. I think you didn't quite understood what he's looking for. his point is to only have decimals if there are decimal numbers.