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.
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.
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.
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.