how do i write a program that the output is coming with decimal numbers? I want to Truncate the decimal numbers in the output. How do i do that?

Printable View

- 11-21-2008, 05:38 PMgbadeTruncating decimal numbers in the output
how do i write a program that the output is coming with decimal numbers? I want to Truncate the decimal numbers in the output. How do i do that?

- 11-21-2008, 05:48 PMxcallmejudasx
what? If your saying you want your output to be a decimal number then just use double instead of int. Check the Math class. I know there is a Math.ceil, Math.floor which will round up/down and there should be something similar to Math.trunc that will accomplish what you want.

- 11-21-2008, 06:25 PMsai
Hi check out this sample code u can use Math.round(double);

public class Truncate {

public static void main(String args[])

{

double i=10;

System.out.println(Math.round(i));

}

}