将字符串与 ruby​​ 中的数字连接起来 [英] Concatenating string with number in ruby

查看:62
本文介绍了将字符串与 ruby​​ 中的数字连接起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全是 ruby​​ 初学者,所以这是一个非常新手的问题.

I am total begineer in ruby so its very novice question.

我正在尝试将字符串与如下所示的浮点值连接起来,然后打印出来.

I am trying to concatenate a string with a float value like follows and then printing it.

puts " Total Revenue of East Cost: " + total_revenue_of_east_cost 

total_revenue_of_east_cost 是一个保存浮点值的变量,我该如何打印?

total_revenue_of_east_cost is a variable holding float value, how i can make it print?

推荐答案

这并不完全是串联,但它可以完成您想做的工作:

This isn't exactly concatenation but it will do the job you want to do:

puts " Total Revenue of East Cost: #{total_revenue_of_east_cost}"

从技术上讲,这是插值.不同之处在于连接添加到字符串的末尾,而插值计算一些代码并将其插入到字符串中.在这种情况下,插入位于字符串的末尾.

Technically, this is interpolation. The difference is that concatenation adds to the end of a string, where as interpolation evaluates a bit of code and inserts it into the string. In this case, the insertion comes at the end of your string.

Ruby 将评估字符串中大括号之间的任何内容,其中左大括号前面是八字串.

Ruby will evaluate anything between braces in a string where the opening brace is preceded by an octothorpe.

这篇关于将字符串与 ruby​​ 中的数字连接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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