code: Double truncate(Number numberValue) {
      // http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html
      double doubleValue = numberValue.doubleValue();
      if (truncateEnabled) {
        final int exponent = Math.getExponent(doubleValue);
        if (Double.isNaN(doubleValue)) {
          doubleValue = 0.0;
        } else if (exponent >= MAX_EXPONENT) {
          doubleValue = (doubleValue < 0.0) ? -MAX_VALUE : MAX_VALUE;
        } else if (exponent <= MIN_EXPONENT) {
          doubleValue = 0.0;
        }
      }
      return doubleValue;
    }
docs: Adjust a double value so it can be successfully written to cloudwatch. This involves capping
  values with large exponents to an experimentally determined max value and converting values
  with large negative exponents to 0. In addition, NaN values will be converted to 0.