我想要一些功能可以返回12000 功能 => 12000.0 我在网上搜索,但找不到任何功能。 问候, Suresh 解决方案 类似于: def cvt(输入): 如果输入.lower() .endswith(''k''):return float(输入[: - 1])* 1000 Suresh Jeevanandam写道:我想将字符串转换为浮点值。该字符串包含工程符号。例如, s ='''12k'' 我想要一些能返回12000的函数/> function(s) => 12000.0 我在网上搜索,但找不到任何功能。 问候, Suresh port this this http://api.rubyonrails。 com / classes / A ... ric / Bytes.html On Tue,2005年12月20日19:07:02 +0530, Suresh Jeevanandam< jm ******* @ gmail.com>写道: 我想将字符串转换为浮点值。该字符串包含工程符号。例如, s ='''12k'' 我想要一些能返回12000的函数/> function(s) => 12000.0 我搜索了网页,但找不到任何功能。 它应该很容易,如果你能准确定义什么 " ;包含工程符号意味着;-) 问候, Bengt Richter Hi,I want to convert a string to float value. The string containsengineering symbols.For example, s = ''12k'' I want some function which would return 12000function(s)=> 12000.0I searched the web, but could not find any function. regards,Suresh 解决方案 Something like: def cvt(input):if input.lower().endswith(''k''): return float(input[:-1])*1000Suresh Jeevanandam wrote: Hi, I want to convert a string to float value. The string contains engineering symbols. For example, s = ''12k'' I want some function which would return 12000 function(s) => 12000.0 I searched the web, but could not find any function. regards, Suresh port this http://api.rubyonrails.com/classes/A...ric/Bytes.html On Tue, 20 Dec 2005 19:07:02 +0530, Suresh Jeevanandam <jm*******@gmail.com> wrote: Hi,I want to convert a string to float value. The string containsengineering symbols.For example,s = ''12k''I want some function which would return 12000function(s)=> 12000.0I searched the web, but could not find any function.It should be easy enough, if you can define precisely what"contains engineering symbols" means ;-) Regards,Bengt Richter 这篇关于解析工程符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 17:53