英文:
How to convert "10_000_00" string class to 10_000_00 Integer class
问题
如何将以下“整数”字符串转换为它们下划线分隔的Integer类对应项?
示例:
"10_000_00" => 10_000_00
"500_000_00" => 500_000_00
等等。
英文:
How can I convert the following "integer" strings into there underscored Integer class counter parts?
Examples:
"10_000_00" => 10_000_00
"500_000_00" => 500_000_00
etc. etc
答案1
得分: 3
String#to_i
将数字的字符串表示转换为整数:
"10_000_00".to_i
# => 1000000
"500_000_00".to_i
# => 50000000
请注意,整数中的下划线仅仅是在源代码中为了更易读而添加的语法糖,但这些整数并没有特殊之处:
10_000_00 == 1000000
# => true
英文:
String#to_i
translates the string representation of a number to an integer:
"10_000_00".to_i
#=> 1000000
"500_000_00".to_i
#=> 50000000
Note that underscores in integers are only syntactic sugar to make the more readable in source code, but there is nothing special about those integers
10_000_00 == 1000000
#=> true
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论