Casting to a String

Download ruby eBook

Example

123.5.to_s    #=> "123.5"
String(123.5) #=> "123.5"

Usually, String() will just call #to_s.

Methods Kernel#sprintf and String#% behave similar to C:

sprintf("%s", 123.5) #=> "123.5"
"%s" % 123.5 #=> "123.5"
"%d" % 123.5 #=> "123"
"%.2f" % 123.5 #=> "123.50"

Stats

Contributors: 2
2016-03-29
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook