makePrecise method

double makePrecise(
  1. double val
)

Rounds a numeric value to the PrecisionModel grid. Asymmetric Arithmetic Rounding is used, to provide uniform rounding behaviour no matter where the number is on the number line.

This method has no effect on NaN values.

Note: Java's Math#rint uses the "Banker's Rounding" algorithm, which is not suitable for precision operations elsewhere in JTS.

Implementation

double makePrecise(double val) {
  // don't change NaN values
  if (val.isNaN) return val;

  if (modelType == FIXED) {
    return (val * scale).round() / scale;
  }
  // modelType == FLOATING - no rounding necessary
  return val;
}