Can't convert string to float

Hi guys,

I’m having trouble converting string to float.

I get the user input in a html form (input type is text) and then I
have:

input.no_tus.to_f / 100.0

The conversion doesn’t happen. For example:

I had input.no_tus to be 56 and the result for the above code was 0.

Any thoughts?

I tried in irb and it works ok.

This is a part of a camping web app.

regards,
seba

Your code is fine.

input = ‘5’
input.to_f / 100.0

Result:

=> 0.05

Robert H. wrote in post #1144732:

Your code is fine.

input = ‘5’
input.to_f / 100.0

Result:

=> 0.05

I know:(
However, something is causing the to_f not to happen. I have similar
problems with calculating the weighted value:

(input.addition_omission.to_f * 3.0) + (input.term_base.to_f * 3.0) +
(input.transl_mem.to_f * 2.0)

I left others out for brevity, but they’re the same. Here, the input is
html type number and the output is always integer, never float.

regards,
seba

Sebastjan H. wrote in post #1144734:

Robert H. wrote in post #1144732:

Your code is fine.

input = ‘5’
input.to_f / 100.0

Result:

=> 0.05

I know:(
However, something is causing the to_f not to happen. I have similar
problems with calculating the weighted value:

(input.addition_omission.to_f * 3.0) + (input.term_base.to_f * 3.0) +
(input.transl_mem.to_f * 2.0)

I left others out for brevity, but they’re the same. Here, the input is
html type number and the output is always integer, never float.

regards,
seba

The error was in active record types. It works fine now.

regards
seba

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs