Transform to/from GPS using `decimal.Decimal` for precision
181536
def _transform_decimal(cls, value, epoch, scale):
        
        vdec = Decimal(_truncate(value, 12))
        edec = Decimal(_truncate(epoch, 12))
        sdec = Decimal(_truncate(scale, 12))
        return type(value)(cls._transform(vdec, edec, sdec))
835361
function (number, decimals, decPoint, thousandsSep) {

            number = ("" + number).replace(/[^0-9+\-Ee.]/g, "");

            var num        = !isFinite(+number) ? 0 : +number,
                prec       = !isFinite(+decimals) ? 0 : Math.abs(decimals),
                separator  = thousandsSep === undefined ? "," : thousandsSep,
                decimal    = decPoint === undefined ? "." : decPoint,
                toFixedFix = function (n, prec) {
                    var k = Math.pow(10, prec);
                    return "" + (Math.round(n * k) / k).toFixed(prec);
                },

                // Fix for IE parseFloat(0.55).toFixed(0) = 0;
                result     = (prec ? toFixedFix(num, prec) : "" + Math.round(num)).split(".");

            if (result[0].length > 3) {
                result[0] = result[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, separator);
            }

            return result.join(decimal);
        }
1275774
def gps_offset(lat, lon, east, north):
    ''''''
    bearing = math.degrees(math.atan2(east, north))
    distance = math.sqrt(east**2 + north**2)
    return gps_newpos(lat, lon, bearing, distance)
561695
def transform_to(target_datum)
      return self if datum == target_datum
      if helmert = Osgb::Helmert[:"#{self.datum}_to_#{target_datum}"]
        cartesian_coordinates = Osgb::Ellipsoid[self.datum].polar_to_cartesian(@lat.to_radians,@lng.to_radians)
        transformed = helmert.transform(*cartesian_coordinates)
        phi, lambda = Osgb::Ellipsoid[target_datum].cartesian_to_polar(*transformed)
        self.class.new(phi.to_degrees, lambda.to_degrees, target_datum, precision)
      else
        raise Osgb::TransformationError, "Missing helmert transformation for #{self.datum} to #{target_datum}"
      end
    end
1285808
def format_decimal(decimal):
    
    # strip trailing fractional zeros
    normalized = decimal.normalize()
    sign, digits, exponent = normalized.as_tuple()
    if exponent >= 1:
        normalized = normalized.quantize(1)

    return str(normalized)
678765
def format_decimal(self, altitude=None):
        
        coordinates = [str(self.latitude), str(self.longitude)]

        if altitude is None:
            altitude = bool(self.altitude)
        if altitude:
            if not isinstance(altitude, string_compare):
                altitude = 'km'
            coordinates.append(self.format_altitude(altitude))

        return ", ".join(coordinates)
1193786
def coord_from_area(self, x, y, lat, lon, width, ground_width):
		''''''

		pixel_width = ground_width / float(width)
		dx = x * pixel_width
		dy = y * pixel_width

		return mp_util.gps_offset(lat, lon, dx, -dy)
1130876
def to_decimal(number, points=None):
    
    if not is_number(number):
        return number

    number = float(decimal.Decimal(number * 1.))  # can't Decimal an int
    if is_number(points):
        return round(number, points)
    return number
537056
def prepare_fixed_decimal(data, schema):
    """"""
    if not isinstance(data, decimal.Decimal):
        return data
    scale = schema.get('scale', 0)
    size = schema['size']

    # based on https://github.com/apache/avro/pull/82/

    sign, digits, exp = data.as_tuple()

    if -exp > scale:
        raise ValueError(
            'Scale provided in schema does not match the decimal')
    delta = exp + scale
    if delta > 0:
        digits = digits + (0,) * delta

    unscaled_datum = 0
    for digit in digits:
        unscaled_datum = (unscaled_datum * 10) + digit

    bits_req = unscaled_datum.bit_length() + 1

    size_in_bits = size * 8
    offset_bits = size_in_bits - bits_req

    mask = 2 ** size_in_bits - 1
    bit = 1
    for i in range(bits_req):
        mask ^= bit
        bit <<= 1

    if bits_req < 8:
        bytes_req = 1
    else:
        bytes_req = bits_req // 8
        if bits_req % 8 != 0:
            bytes_req += 1

    tmp = MemoryIO()

    if sign:
        unscaled_datum = (1 << bits_req) - unscaled_datum
        unscaled_datum = mask | unscaled_datum
        for index in range(size - 1, -1, -1):
            bits_to_write = unscaled_datum >> (8 * index)
            tmp.write(mk_bits(bits_to_write & 0xff))
    else:
        for i in range(offset_bits // 8):
            tmp.write(mk_bits(0))
        for index in range(bytes_req - 1, -1, -1):
            bits_to_write = unscaled_datum >> (8 * index)
            tmp.write(mk_bits(bits_to_write & 0xff))

    return tmp.getvalue()
194205
def int_gps_time_to_str(t):
    """"""

    if isinstance(t, int):
        return str(t)
    elif isinstance(t, float):
        # Wouldn't this just work generically?
        int_t = int(t)
        if abs(t - int_t) > 0.:
            raise ValueError('Need an integer GPS time, got %s' % str(t))
        return str(int_t)
    elif isinstance(t, lal.LIGOTimeGPS):
        if t.gpsNanoSeconds == 0:
            return str(t.gpsSeconds)
        else:
            raise ValueError('Need an integer GPS time, got %s' % str(t))
    else:
        err_msg = "Didn't understand input type {}".format(type(t))
        raise ValueError(err_msg)
240261
def _inc_lat(self, latitude, delta):
        """"""
        y = self._convert_latitude(latitude)
        y += delta
        return 360 / pi * atan(
            exp((180 - y * 360 / (2 ** self._zoom) / self._size) * pi / 180)) - 90
612907
private String roundToDecimalPlace(double distance, int decimalPlace) {
    numberFormat.setMaximumFractionDigits(decimalPlace);

    return numberFormat.format(distance);
  }
1266152
def tinygps_to_degdec(lat, lng):
    """"""
    x = float(lat[:-5] + '.' + lat[-5:])
    y = float(lng[:-5] + '.' + lng[-5:])

    return x, y
612304
def _control_longitude(self):
        '''  '''

        if self.lonm < 0.0:
            self.lonm = 360.0 + self.lonm
        if self.lonM < 0.0:
            self.lonM = 360.0 + self.lonM
        if self.lonm > 360.0:
            self.lonm = self.lonm - 360.0
        if self.lonM > 360.0:
            self.lonM = self.lonM - 360.0
569654
def adjust_to_360(val, key):
    
    CheckDec = ['_dec', '_lon', '_azimuth', 'dip_direction']
    adjust = False
    for dec_key in CheckDec:
        if dec_key in key:
            if key.endswith(dec_key) or key.endswith('_'):
                adjust = True
    if not val:
        return ''
    elif not adjust:
        return val
    elif adjust:
        new_val = float(val) % 360
        if new_val != float(val):
            print('-I- adjusted {} {} to 0=>360.: {}'.format(key, val, new_val))
        return new_val
1121485
def set_decimal(self, pos, decimal):
        
        if pos < 0 or pos > 3:
            # Ignore out of bounds digits.
            return
        # Set bit 14 (decimal point) based on provided value.
        if decimal:
            self.buffer[pos*2+1] |= (1 << 6)
        else:
            self.buffer[pos*2+1] &= ~(1 << 6)
1317976
def trim_decimals(s, precision=-3):
        
        encoded = s.encode('ascii', 'ignore')
        str_val = ""
        if six.PY3:
            str_val = str(encoded, encoding='ascii', errors='ignore')[:precision]
        else:
            # If precision is 0, this must be handled seperately
            if precision == 0:
                str_val = str(encoded)
            else:
                str_val = str(encoded)[:precision]
        if len(str_val) > 0:
            return float(str_val)
        else:
            return 0