这是我的代码
class Atm
attr_accessor :amount, :rem, :balance
TAX = 0.50
def transaction
@rem = @balance=2000.00
@amount = gets.chomp.to_f
if @amount%5 != 0 || @balance < @amount
"Incorrect Withdrawal Amount(not multiple of 5) or you don't have enough balance"
else
@rem = @balance-(@amount+TAX)
"Successful Transaction"
end
end
end
a=Atm.new
puts "Enter amount for transaction"
puts a.transaction
puts "Your balance is #{a.rem.to_f}"
Run Code Online (Sandbox Code Playgroud)
我的输出是
Enter amount for transaction
100 # user enters this value
Successful Transaction
Your balance is 1899.5
Run Code Online (Sandbox Code Playgroud)
正如你可以看到的输出,'你的余额是1899.5'只显示一位数的精度.我需要帮助来理解和解决问题.我希望输出中有两位数的精度.
还有我如何改进这段代码?
我是新手,学习红宝石.希望能够更好地理解所提出的问题.我不明白使用类似的mixin和可枚举的mixin.我的意思是当我们需要使用它们时,我们不会在课堂中包含这些,对吧?如果我们想比较两个对象,我们只需写x> y.那么明确使用它们的用途是什么?
我安装并运行了我的redis服务器,但是当我使用bundle exec sidekiq它连接sidekiq时会抛出错误消息
在localhost:6379上连接到Redis超时
Redis Server正在端口上运行:6379.
我正在尝试使用twitter的框架来开发自己的网站,我希望我的图像可以随着浏览器大小的减小而调整大小.我很困惑,尝试了一切,但无法想出解决方案,这是我的结构
HTML
<section id="intro">
<div class="row" id="ruby">
<div class="span6" id="heading">
<h1>Journey Into Ruby and Beyond</h1>
<p>A blog about my journey into ruby, my experiences and lots of fun!</p>
</div>
<div class="span6" id="pic" align="right">
<p>Akash Soti<br>RoR Developer<br>@xyz company </p>
</div>
</section><!--/intro-->
Run Code Online (Sandbox Code Playgroud)
CSS
#ruby.row{
margin-left: 0px;
padding-right: 0px;
padding-bottom: 0px;
}
#pic{
background: url(img/Akash.png);
background-repeat: no-repeat;
height: 150px;
width: 200px;
margin-left: 200px;
}
#pic img{
max-width:100% ;
max-height:100% ;
display:block;
}
#pic p{
position: relative;
right: 110px;
margin-top: 90px;
margin-left: 0px;
text-align: …Run Code Online (Sandbox Code Playgroud) ruby ×2
comparable ×1
css ×1
css3 ×1
enumerable ×1
html ×1
html5 ×1
mixins ×1
redis ×1
sidekiq ×1