MCPcopy
hub / github.com/waditu/tushare / make_float

Method make_float

tushare/util/demjson.py:3153–3174  ·  view source on GitHub ↗

Converts a string into a float or decimal value.

( self, s, sign='+' )

Source from the content-addressed store, hash-verified

3151 return f
3152
3153 def make_float( self, s, sign='+' ):
3154 """Converts a string into a float or decimal value."""
3155 if decimal and self.float_type == NUMBER_DECIMAL:
3156 return self.make_decimal( s, sign )
3157
3158 if s.startswith('-') or s.startswith('+'):
3159 sign = s[0]
3160 s = s[1:]
3161 elif isinstance(sign, (int,long)):
3162 if sign < 0:
3163 sign = '-'
3164 else:
3165 sign = '+'
3166
3167 try:
3168 f = float(s)
3169 except ValueError:
3170 f = nan
3171 else:
3172 if sign=='-':
3173 f *= -1
3174 return f
3175
3176 @property
3177 def leading_zero_radix(self):

Callers 3

make_intMethod · 0.95
make_decimalMethod · 0.95
decode_numberMethod · 0.80

Calls 2

make_decimalMethod · 0.95
startswithMethod · 0.80

Tested by

no test coverage detected