Truncates a decimal to 3 decimal places if numeric
 and remove trailing zeros, if more than one decimal place.
 returns a string
974639
def truncate_decimal(a_cell)
    if(a_cell.is_a?(Numeric))
      a_cell = truncate_decimal_to_string(a_cell, 3)
      # Truncate zeros (unless there is only 1 decimal place)
      # eg. 12.10 => 12.1
      #     12.0  => 12.0
      a_cell = BigDecimal.new(a_cell).to_s("F")
    end
    a_cell
  end
791320
def trim_zeros(self):
              
        tmp = self.numpy()
        f = len(self)-len(_numpy.trim_zeros(tmp, trim='f'))
        b = len(self)-len(_numpy.trim_zeros(tmp, trim='b'))
        return self[f:len(self)-b]
537345
def round_to_n_decimal_places(array, n=3):
    
    # check if in scientific notation
    if issubclass(array.__class__, float) and '%.e'%array == str(array):
        return array # do nothing

    shape = np.shape(array)
    out = ((np.atleast_1d(array) * 10**n).round().astype('int') / (10.**n))
    return out.reshape(shape)
489962
function truncate(str, maxLength) {
	maxLength = maxLength || 300;

	if (str.length > maxLength) {
		var index = str.indexOf('>');
		str = str.substring(0, index + 1);
	}

	return str;
}
500011
def parse_decimal_part(str)
      map = if str.index('割')
              Numeja::JA_割合用小数
            else
              Numeja::JA_小数
            end
      keys = map.keys()
      keys.reduce(0) do |t, ja_digit|
        index = str.index(ja_digit)
        break t if index.nil?
        unit = str.slice!(0, index)
        str.slice!(0, 1)
        t += (unit.to_f * map[ja_digit])
        t
      end
    end
633682
def truncate(string, index):
    """"""
    if len(string) > index and index > 0:
        string = string[:index - 1] + u('…')
    return string
118473
function cutNumber() {
        if (isFloat()) {
          var numerator = parseFloat(cutFloat());

          if (str[0] === '/') {
            // rational real part
            str = str.slice(1);

            if (isFloat()) {
              var denominator = parseFloat(cutFloat());
              return self.$Rational(numerator, denominator);
            } else {
              // reverting '/'
              str = '/' + str;
              return numerator;
            }
          } else {
            // float real part, no denominator
            return numerator;
          }
        } else {
          return null;
        }
      }
84679
def truncatechars(value, arg):
    
    try:
        length = int(arg)
    except ValueError: # Invalid literal for int().
        return value # Fail silently.
    if len(value) > length:
        return value[:length] + '...'
    return value
1361882
def _stringify_number(v):
    '''
    
    '''
    if isinstance(v, (float, Decimal)):
        if math.isinf(v) and v > 0:
            v = 'Infinity'
        elif math.isinf(v) and v < 0:
            v = '-Infinity'
        else:
            v = '{:f}'.format(v)
    elif isinstance(v, BinarySize):
        v = '{:d}'.format(int(v))
    elif isinstance(v, int):
        v = '{:d}'.format(v)
    else:
        v = str(v)
    return v
183536
def trunc_str(s: str) -> str:
    """"""
    if len(s) > max_str_size:
        i = max(0, (max_str_size - 3) // 2)
        j = max(0, max_str_size - 3 - i)
        s = s[:i] + "..." + s[-j:]
    return s
701924
def truncate(value: Decimal, n_digits: int) -> Decimal:
    """"""
    return Decimal(math.trunc(value * (10 ** n_digits))) / (10 ** n_digits)
1373175
def trunc_if_integer(n: Any) -> Any:
    
    if n == int(n):
        return int(n)
    return n
914020
function decimalLength(n) {
	let ns = cleanNumber(n).toString();
	let ems = ns.match(/e([\+\-]\d+)$/);
	let e = 0;
	if (ems && ems[1]) e = parseInt(ems[1]);
	ns = ns.replace(/e[\-\+]\d+$/, '');	
	let parts = ns.split('.', 2);
	if (parts.length === 1) return -e;
	return parts[1].length - e;
}
987570
def truncate(string, length, ellipsis="…"):
    
    if len(string) > length:
        return string[: length - len(ellipsis)] + ellipsis
    return string
299383
def truncate_default(str)
      return str unless str.kind_of? String
      str.sub!(/^'(.*)'$/m,'\1')
      str = "#{str[0..10]}..." if str.size > 10
      str.inspect
    end
564996
def float_str(f, min_digits=2, max_digits=6):
    
    if f >= 1 or f <= 0:
        return str(round_float(f, min_digits))
    start_str = str(round_float(f, max_digits))
    digits = start_str.split(".")[1]
    non_zero_indices = []
    for i, digit in enumerate(digits):
        if digit != "0":
            non_zero_indices.append(i + 1)
    # Only saw 0s.
    if len(non_zero_indices) == 0:
        num_digits = min_digits
    else:
        # Of the non-zero digits, pick the num_digit'th of those (including any zeros)
        min_non_zero_indices = range(non_zero_indices[0], non_zero_indices[-1] + 1)[:min_digits]
        num_digits = min_non_zero_indices[-1]
    return str(round_float(f, num_digits))
895756
function truncateString(str, max) {

  str = str != null ? str : ''
  str = String(str)

  if(max == Infinity) return str

  var i = 0
  var wwidth = 0
  while (i < str.length) {
    var w = wcwidth(str.charAt(i))
    if(w + wwidth > max)
      break
    wwidth += w
    ++i
  }
  return str.slice(0, i)
}