private long convertUTMToMGRS(long Zone,double Latitude,double Easting,double Northing,long Precision){
  double grid_easting;
  double grid_northing;
  long[] letters=new long[MGRS_LETTERS];
  double divisor;
  long error_code;
  divisor=Math.pow(10.0,(5 - Precision));
  Easting=roundMGRS(Easting / divisor) * divisor;
  Northing=roundMGRS(Northing / divisor) * divisor;
  getGridValues(Zone);
  error_code=getLatitudeLetter(Latitude);
  letters[0]=getLastLetter();
  if (error_code == MGRS_NO_ERROR) {
    grid_northing=Northing;
    if (grid_northing == 1.e7)     grid_northing=grid_northing - 1.0;
    while (grid_northing >= TWOMIL) {
      grid_northing=grid_northing - TWOMIL;
    }
    grid_northing=grid_northing + false_northing;
    if (grid_northing >= TWOMIL)     grid_northing=grid_northing - TWOMIL;
    letters[2]=(long)(grid_northing / ONEHT);
    if (letters[2] > LETTER_H)     letters[2]=letters[2] + 1;
    if (letters[2] > LETTER_N)     letters[2]=letters[2] + 1;
    grid_easting=Easting;
    if (((letters[0] == LETTER_V) && (Zone == 31)) && (grid_easting == 500000.0))     grid_easting=grid_easting - 1.0;
    letters[1]=ltr2_low_value + ((long)(grid_easting / ONEHT) - 1);
    if ((ltr2_low_value == LETTER_J) && (letters[1] > LETTER_N))     letters[1]=letters[1] + 1;
    makeMGRSString(Zone,letters,Easting,Northing,Precision);
  }
  return error_code;
}

private long convertUTMToMGRS ( long Zone , double Latitude , double Easting , double Northing , long Precision ) { double grid_easting ; double grid_northing ; long [ ] letters = new long [ MGRS_LETTERS ] ; double divisor ; long error_code ; divisor = Math . pow ( 10.0 , ( 5 - Precision ) ) ; Easting = roundMGRS ( Easting / divisor ) * divisor ; Northing = roundMGRS ( Northing / divisor ) * divisor ; getGridValues ( Zone ) ; error_code = getLatitudeLetter ( Latitude ) ; letters [ 0 ] = getLastLetter ( ) ; if ( error_code == MGRS_NO_ERROR ) { grid_northing = Northing ; if ( grid_northing == 1.e7 ) grid_northing = grid_northing - 1.0 ; while ( grid_northing >= TWOMIL ) { grid_northing = grid_northing - TWOMIL ; } grid_northing = grid_northing + false_northing ; if ( grid_northing >= TWOMIL ) grid_northing = grid_northing - TWOMIL ; letters [ 2 ] = ( long ) ( grid_northing / ONEHT ) ; if ( letters [ 2 ] > LETTER_H ) letters [ 2 ] = letters [ 2 ] + 1 ; if ( letters [ 2 ] > LETTER_N ) letters [ 2 ] = letters [ 2 ] + 1 ; grid_easting = Easting ; if ( ( ( letters [ 0 ] == LETTER_V ) && ( Zone == 31 ) ) && ( grid_easting == 500000.0 ) ) grid_easting = grid_easting - 1.0 ; letters [ 1 ] = ltr2_low_value + ( ( long ) ( grid_easting / ONEHT ) - 1 ) ; if ( ( ltr2_low_value == LETTER_J ) && ( letters [ 1 ] > LETTER_N ) ) letters [ 1 ] = letters [ 1 ] + 1 ; makeMGRSString ( Zone , letters , Easting , Northing , Precision ) ; } return error_code ; }
the function utm_to_mgrs calculates an mgrs coordinate string based on the zone , latitude , easting and northing .
