private long makeMGRSString(long Zone,long[] Letters,double Easting,double Northing,long Precision){
  int j;
  double divisor;
  long east;
  long north;
  long error_code=MGRS_NO_ERROR;
  if (Zone != 0)   MGRSString=String.format("%02d",Zone);
 else   MGRSString="  ";
  for (j=0; j < 3; j++) {
    if (Letters[j] < 0 || Letters[j] > 26)     return MGRS_ZONE_ERROR;
    MGRSString=MGRSString + alphabet.charAt((int)Letters[j]);
  }
  divisor=Math.pow(10.0,(5 - Precision));
  Easting=Easting % 100000.0;
  if (Easting >= 99999.5)   Easting=99999.0;
  east=(long)(Easting / divisor);
  Integer iEast=(int)east;
  String sEast=iEast.toString();
  if (sEast.length() > Precision)   sEast=sEast.substring(0,(int)Precision - 1);
 else {
    int i;
    int length=sEast.length();
    for (i=0; i < Precision - length; i++) {
      sEast="0" + sEast;
    }
  }
  MGRSString=MGRSString + " " + sEast;
  Northing=Northing % 100000.0;
  if (Northing >= 99999.5)   Northing=99999.0;
  north=(long)(Northing / divisor);
  Integer iNorth=(int)north;
  String sNorth=iNorth.toString();
  if (sNorth.length() > Precision)   sNorth=sNorth.substring(0,(int)Precision - 1);
 else {
    int i;
    int length=sNorth.length();
    for (i=0; i < Precision - length; i++) {
      sNorth="0" + sNorth;
    }
  }
  MGRSString=MGRSString + " " + sNorth;
  return (error_code);
}

private long makeMGRSString ( long Zone , long [ ] Letters , double Easting , double Northing , long Precision ) { int j ; double divisor ; long east ; long north ; long error_code = MGRS_NO_ERROR ; if ( Zone != 0 ) MGRSString = String . format ( "%02d" , Zone ) ; else MGRSString = "  " ; for ( j = 0 ; j < 3 ; j ++ ) { if ( Letters [ j ] < 0 || Letters [ j ] > 26 ) return MGRS_ZONE_ERROR ; MGRSString = MGRSString + alphabet . charAt ( ( int ) Letters [ j ] ) ; } divisor = Math . pow ( 10.0 , ( 5 - Precision ) ) ; Easting = Easting % 100000.0 ; if ( Easting >= 99999.5 ) Easting = 99999.0 ; east = ( long ) ( Easting / divisor ) ; Integer iEast = ( int ) east ; String sEast = iEast . toString ( ) ; if ( sEast . length ( ) > Precision ) sEast = sEast . substring ( 0 , ( int ) Precision - 1 ) ; else { int i ; int length = sEast . length ( ) ; for ( i = 0 ; i < Precision - length ; i ++ ) { sEast = "0" + sEast ; } } MGRSString = MGRSString + " " + sEast ; Northing = Northing % 100000.0 ; if ( Northing >= 99999.5 ) Northing = 99999.0 ; north = ( long ) ( Northing / divisor ) ; Integer iNorth = ( int ) north ; String sNorth = iNorth . toString ( ) ; if ( sNorth . length ( ) > Precision ) sNorth = sNorth . substring ( 0 , ( int ) Precision - 1 ) ; else { int i ; int length = sNorth . length ( ) ; for ( i = 0 ; i < Precision - length ; i ++ ) { sNorth = "0" + sNorth ; } } MGRSString = MGRSString + " " + sNorth ; return ( error_code ) ; }
the function make_mgrs_string constructs an mgrs string from its component parts .
