B
B
Bogdan2017-11-20 16:01:28
ruby
Bogdan, 2017-11-20 16:01:28

String to number - incorrectly processed?

Hello. Tell me how to solve this problem correctly? When translating and truncating the length after the decimal point, does it incorrectly process the number ?
puts ('2.01').to_f.truncate(3) # 2.009

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Tarasenko, 2017-11-20
@Arlantir

And what is the task?
puts sprintf("%3f", '2.01').to_f # 2.01

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question