Sprintf is broken in RubyMotion

Ruby noob, just received and installed RubyMotion, created my first program, and it's hard for me to get the Time (sample) application to work.

Whenever I try to format a string using either a sprint or another form (sorry, I don’t know the name), I just return my format string.

i.e. (from the console when my application is running in Simulator)

Build ./build/iPhoneSimulator-5.1-Development
Simulate ./build/iPhoneSimulator-5.1-Development/Timer.app
(main)>> @time = 0.1
=> 0.0999999940395355
(main)>> string = sprintf("%.1f", @time)
=> "%.1f"
(main)>> string
=> "%.1f"
(main)>> "%.1f" % @time 
=> "%.1f"
(main)>> 

The same result in a real application in a simulator.

I have the default ruby ​​installed on my Mac, but if I try to run the ruby ​​test file (type "% 05d"% 123), I get the expected results.

/usr/bin/ruby -v 
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
/Library/RubyMotion/bin/ruby -v
MacRuby 0.12 (ruby 1.9.2) [universal-darwin11.0, i386]

Running on Lion 10.7.3, any advice or ideas appreciated.

Thank.

+3
source share
1 answer

5/9/12 . , RubyMotion 1.3 ( sudo motion update), .

5/8/12: , ​​ .

. - ( %d sprintf):

@time = 0.1
sprintf("%d", (@time * 10).round).insert(-2, '.')
+1

All Articles