package tools;

public class Format {
  private Format() {}           // defeat instantiation

  public static double round(double d, int place) {
    if (d==0) return d;

    place = (int)Math.pow(10,place);
    
    if (d<0) {
      d *= place;        // multiply by 10^place (shift decimal by <place>)
      d = Math.ceil(d);  // truncate decimal
      d /= place;        // divide by 10^place (shift decimal back)
    }

    if (d>0) {
      d *= place;        // multiply by 10^place (shift decimal by <place>)
      d = Math.floor(d); // truncate decimal
      d /= place;        // divide by 10^place (shift decimal back)
    }

    return d;
  }
}
