How can I explicitly tell python to read a decimal number using the point or the comma as a decimal separator? I don't know the localization settings of the PC that will run my script, and this should not influence my application, I only want to say:
f = read_float_with_point("3.14")
or
f = read_float_with_comma("3,14")
I think that writing
def read_float_with_comma(num):
return float(num.replace(",", ".")
is not secure, because I don't know the locale settings!
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…