PDA

View Full Version : Problem Handling Long Data types in GUI



saneha
04-27-2011, 06:29 AM
Sir,

I have written a GUI based Address Book program where i have used long data type to store mobile number. The GUI is showing a .0 at the end of each mobile # as if it is a decimal value.

The Mobile # values in the database slightly differ with the values displayed in the GUI as well.

Please suggest a solution.

Vuhelper
04-27-2011, 06:30 AM
You can use DecimalFormat to format the out put of numbers

package testproject;

import java.text.DecimalFormat;

public class Main {

public static void main(String[] args) {
double numberToRound = 12345.6789;

DecimalFormat df = new DecimalFormat("0");
System.out.println("Rounded number = " + df.format(numberToRound));
}
}

The output will be as
Rounded number = 12345

Let me know if you are unable to solve the problem with this.