Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python convert number with a comma and decimal to a float

from locale import atof, setlocale, LC_NUMERIC
setlocale(LC_NUMERIC, '') # set to your default locale; for me this is
# 'English_Canada.1252'. Or you could explicitly specify a locale in which floats
# are formatted the way that you describe, if that's not how your locale works :)
atof('123,456') # 123456.0
# To demonstrate, let's explicitly try a locale in which the comma is a
# decimal point:
setlocale(LC_NUMERIC, 'French_Canada.1252')
atof('123,456') # 123.456
Comment

PREVIOUS NEXT
Code Example
Python :: dataframe partition dataset based on column 
Python :: how to check if string ends with specific characters in python 
Python :: python suppress print output from function 
Python :: getting a column that corresponds to the average of two columns in pandas 
Python :: django.db.utils.IntegrityError: NOT NULL constraint failed 
Python :: arch python 
Python :: Python Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming 
Python :: sublime autocomplete python 
Python :: class views django slug 
Python :: python loop function 
Python :: rezise object pygame 
Python :: remove percentage in python 
Python :: pyplot histogram labels in center 
Python :: img_sm = pygame.transform.scale(img, (32, 32)) 
Python :: code error correction 
Python :: draw a bow tie in python 
Python :: python - retrieve unconnected node pairs 
Python :: iterate over meta tag python 
Python :: rapids - convert nerworkx to cugraph 
Shell :: install git on amazon linux 
Shell :: yarn emojis 
Shell :: postgres status ubuntu 
Shell :: error gyp ERR! stack Error: not found: make 
Shell :: apache check config 
Shell :: install shutil 
Shell :: firewalld not running centos 7 
Shell :: install wps ubuntu 20.04 multilanguage 
Shell :: m1 pod install 
Shell :: pip install beautiful soup 
Shell :: install apollo 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =