I am learning to program in Ruby, and to go training, I use Uri Online Judge, where I solve exercises that are presented, I make the code in some language that the platform accepts (in this case Ruby) and then I send it to the system , but the output has to be exactly the same as it is displayed, such as displaying two decimal places (two numbers after the period), it can not be anything more or less.
I'm having trouble making Ruby display decimal places.
As for example the number 1051 (I'm having difficulties in other exercises too, but this was the most recent one), the code is:
a = 1000 * (8/100.0)
b = 1500 * (18/100.0)
s = gets.to_f
if s >= 0 and s <= 2000
puts "Isento"
elsif s > 2000 and s <= 3000
s -= 2000
s *= 8/100.0
puts "R$ #{s.round 2}\n"
elsif s > 3000 and s <= 4500
s -= 3000
s *= 18/100.0
s += a
puts "R$ #{s.round 2}\n"
elsif s > 4500
s -= 4500
s *= 28/100.0
s += a + b
puts "R$ #{s.round 2}\n"
end
It should display two decimal places, but when the output would / should display decimal places with "0", it does not display. I have already added the variable with 0.001 but it still displays only 1 decimal place in case of zeros.
How can I resolve this, or is it a bug from Ruby itself?
output example submitted by the URI: