Integer formatting class-method.

        - x will be float-converted and then used.
190656
def _fmt_int(cls, x, **kw):
        
        return str(int(round(cls._to_float(x))))
176437
def _cast(self, value):
        
        if value.isdigit():
            value = int(value)
        elif re.compile("^\d+\.\d+").match(value):
            value = float(value)
        return value
187811
def __to_format(jd: float, fmt: str) -> float:
    
    if fmt.lower() == 'jd':
        return jd
    elif fmt.lower() == 'mjd':
        return jd - 2400000.5
    elif fmt.lower() == 'rjd':
        return jd - 2400000
    else:
        raise ValueError('Invalid Format')
22497
def do_int(value, default=0):
    
    try:
        return int(value)
    except (TypeError, ValueError):
        # this quirk is necessary so that "42.23"|int gives 42.
        try:
            return int(float(value))
        except (TypeError, ValueError):
            return default
472219
def type_converter(text):
    
    if text.isdigit():
        return int(text), int

    try:
        return float(text), float
    except ValueError:
        return text, STRING_TYPE
161562
def cast_int(x):
    
    try:
        x = int(x)
    except ValueError:
        try:
            x = x.strip()
        except AttributeError as e:
            logger_misc.warn("parse_str: AttributeError: String not number or word, {}, {}".format(x, e))
    return x
142428
def format_float(x, max_width):
    '''
    '''
    # width of (whole part + 1 (to avoid zero)) + 1 because int floors, not ceils
    whole_width = int(math.log10(abs(x) + 1)) + 1
    # for +/- sign
    sign_width = 1 if x < 0 else 0
    # for . if we show it
    decimal_point_width = 1 if max_width >= whole_width else 0
    return '%.*f' % (max_width - whole_width - sign_width - decimal_point_width, x)
423458
def _fmt_exp(cls, x, **kw):
        
        n = kw.get('n')
        return '%.*e' % (n, cls._to_float(x))
1182028
def _get_x(self, kwargs):
        '''
        
        '''
        if 'x' in kwargs:
            return round(float(kwargs['x']), 6)
        elif self._element_x in kwargs:
            return round(float(kwargs[self._element_x]), 6)
        elif self._type == 3 and self._element_1mx in kwargs:
            return round(1. - float(kwargs[self._element_1mx]), 6)
        else:
            raise TypeError()
723456
def _to_numeric(val):
    
    if isinstance(val, (int, float, datetime.datetime, datetime.timedelta)):
        return val
    return float(val)
1072159
def _F(self, X):
        
        if isinstance(X, int) or isinstance(X, float):
            if X < 1 and X > 0:
                a = 1/(X**2-1)*(1-2/np.sqrt(1-X**2)*np.arctanh(np.sqrt((1-X)/(1+X))))
            elif X == 1:
                a = 1./3
            elif X > 1:
                a = 1/(X**2-1)*(1-2/np.sqrt(X**2-1)*np.arctan(np.sqrt((X-1)/(1+X))))
            else:  # X == 0:
                c = 0.0000001
                a = 1/(-1)*(1-2/np.sqrt(1)*np.arctanh(np.sqrt((1-c)/(1+c))))

        else:
            a = np.empty_like(X)
            x = X[(X < 1) & (X > 0)]
            a[(X < 1) & (X > 0)] = 1/(x**2-1)*(1-2/np.sqrt(1-x**2)*np.arctanh(np.sqrt((1-x)/(1+x))))

            a[X == 1] = 1./3.

            x = X[X > 1]
            a[X > 1] = 1/(x**2-1)*(1-2/np.sqrt(x**2-1)*np.arctan(np.sqrt((x-1)/(1+x))))
            # a[X>y] = 0

            c = 0.0000001
            a[X == 0] = 1/(-1)*(1-2/np.sqrt(1)*np.arctanh(np.sqrt((1-c)/(1+c))))
        return a
1163076
@Override
    public Float fromString(Class targetClass, String s)
    {
        try
        {
            if (s == null)
            {
                return null;
            }
            Float f = new Float(s);
            return f;
        }
        catch (NumberFormatException e)
        {
            log.error("Number format exception, Caused by {}.", e);
            throw new PropertyAccessException(e);
        }
    }
931778
private static function toFloat($x)
    {
        if (is_float($x)) return $x;
        if (is_int($x)) return $x;
        if (is_string($x)) {
            $r = Rational::parse($x);
            return $r->p/$r->q;
        }
        throw new SyntaxErrorException();
    }
1232554
def cast_float(x):
    
    try:
        x = float(x)
    except ValueError:
        try:
            x = x.strip()
        except AttributeError as e:
            logger_misc.warn("parse_str: AttributeError: String not number or word, {}, {}".format(x, e))
    return x
656365
def _fmt_float(cls, x, **kw):
        
        n = kw.get('n')
        return '%.*f' % (n, cls._to_float(x))
670582
def _format_number_si(num, n_signif_figures):
    """"""
    if math.isnan(num) or math.isinf(num):
        return str(num)
    leading, exp = '{:E}'.format(num).split('E')
    leading = round(float(leading), n_signif_figures - 1)
    exp = exp[:1] + exp[2:] if exp[1] == '0' else exp
    formatted = '{}e{}'.format(leading, exp.lstrip('+'))
    return formatted
1037884
def float_to_decimal(f):
    
    n, d = f.as_integer_ratio()
    numerator, denominator = Decimal(n), Decimal(d)
    return DECIMAL_CONTEXT.divide(numerator, denominator)