将字符串数字(以 word 格式)转换为整数 ruby [英] Convert string numbers( in word format) to integer ruby

查看:39
本文介绍了将字符串数字(以 word 格式)转换为整数 ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有一个字符串 10,是否可以在 Ruby 中将其转换为整数 10?(也许在导轨中?)

If you have a string ten, is it possible to convert it to an integer 10 in Ruby? (maybe in rails?)

我重视 tryruby.org 上的开发人员,在他们的教程这里中,特别说to_i 将事物转换为整数(数字.)"我想知道他们为什么不说to_i 将字符串转换为整数(数字)."

I value the developers at tryruby.org, and in their tutorial here, it specifically says "to_i converts things to integers (numbers.)" I am wondering why they didn't say "to_i converts STRINGS to integers (numbers.)"

哪些变量类型可以从它们的类型转换为整数?

What variable types can be converted from their type to an integer?

推荐答案

查看 这个 gem处理单词到数字的转换.

Check out this gem for handling word to number conversions.

来自自述文件:

require 'numbers_in_words'
require 'numbers_in_words/duck_punch'

112.in_words
#=> one hundred and twelve
"Seventy million, five-hundred and fifty six thousand point eight nine three".in_numbers
#=> 70556000.893

这篇关于将字符串数字(以 word 格式)转换为整数 ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆