wolf
wolf

Reputation: 3

How can i cast a float variable (0.0) in a string class

i have a value returned in json of float type like 0.0 of Float Class

this look good, but when I try to convert to string it change to "0.0"

The Console shows this :

irb(main):080:0> commission.class
=> Float
irb(main):081:0> commission.to_s
=> "0.0"
irb(main):082:0> commission.class
=> Float
irb(main):083:0> commission.class
=> Float

Can anyone help me to understand this behavior. Why class are still float?

Upvotes: 0

Views: 54

Answers (1)

steenslag
steenslag

Reputation: 80065

In Ruby, the Class of an Object does not change. Ever. Some methods can result in a new object from another class. The original object does not transform or cease to exist.

Upvotes: 3

Related Questions