public static double[] roundToSignificantDigits(double x,double y,int nSignif){
  double[] rounded=new double[2];
  double diff=Math.abs(x - y);
  if (diff < 1e-16) {
    rounded[0]=x;
    rounded[1]=y;
    return rounded;
  }
  if (diff > 1) {
    rounded[0]=Math.rint(x * Math.pow(10.0,nSignif)) / Math.pow(10.0,nSignif);
    rounded[1]=Math.rint(y * Math.pow(10.0,nSignif)) / Math.pow(10.0,nSignif);
    return rounded;
  }
 else {
    int nzeros=(int)(Math.ceil(Math.abs(Math.log10(diff))) + nSignif);
    rounded[0]=Math.rint(x * Math.pow(10.0,nzeros)) / Math.pow(10.0,nzeros);
    rounded[1]=Math.rint(y * Math.pow(10.0,nzeros)) / Math.pow(10.0,nzeros);
    return rounded;
  }
}

public static double [ ] roundToSignificantDigits ( double x , double y , int nSignif ) { double [ ] rounded = new double [ 2 ] ; double diff = Math . abs ( x - y ) ; if ( diff < 1e-16 ) { rounded [ 0 ] = x ; rounded [ 1 ] = y ; return rounded ; } if ( diff > 1 ) { rounded [ 0 ] = Math . rint ( x * Math . pow ( 10.0 , nSignif ) ) / Math . pow ( 10.0 , nSignif ) ; rounded [ 1 ] = Math . rint ( y * Math . pow ( 10.0 , nSignif ) ) / Math . pow ( 10.0 , nSignif ) ; return rounded ; } else { int nzeros = ( int ) ( Math . ceil ( Math . abs ( Math . log10 ( diff ) ) ) + nSignif ) ; rounded [ 0 ] = Math . rint ( x * Math . pow ( 10.0 , nzeros ) ) / Math . pow ( 10.0 , nzeros ) ; rounded [ 1 ] = Math . rint ( y * Math . pow ( 10.0 , nzeros ) ) / Math . pow ( 10.0 , nzeros ) ; return rounded ; } }
function to round x and y to a number of digits enough to show the difference in range this is for pretty printing only .
