1

I have a program and a layout for coordinate input.

I'm entering latitude and longitude values. When the cordinates are close to each other (for example lat1:21.424521 and lat2:21.424534 ), and it gets really annoying to input all coordinates.

Does anyone know how can I get first two digits of the first values so i dont have write them multiple times.

SteBra
  • 4,188
  • 6
  • 37
  • 68
Capan
  • 686
  • 1
  • 14
  • 32

2 Answers2

0
double lat1 = 21.424521;
lat1 = new DecimalFormat("##.##").format(lat1));

This will, for example, trimm it down to two decimals. If you want only 2 digits, you would do it like this:

lat1 = new DecimalFormat("##").format(lat1));

And so on...

SteBra
  • 4,188
  • 6
  • 37
  • 68
0
new DecimalFormat("#.##").format(dblVar);  

That is what you need, if I understand your question correctly.

Example:

DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
s = df.format(lat);  // or df.format(lng);

Source:

How can I truncate a double to only two decimal places in Java?

Community
  • 1
  • 1
An SO User
  • 24,612
  • 35
  • 133
  • 221