round() on floats

60 views
Skip to first unread message

Eugene Alfonso

unread,
Sep 27, 2012, 3:59:06 PM9/27/12
to rubym...@googlegroups.com
Not sure if im just losing my mind or something, but I cant get round() to work on floats.

in RM REPL: 

2.3345.round 
=> 2
2.3345.round(2)
=> 2.33449935913086
2.3345.round 2
=> 2.33449935913086

in IRB:

2.3345.round
=> 2
2.3345.round(2)
=> 2.33
2.3345.round 2
=> 2.33

Im kinda new to ruby but I imagine this should've work?

Mark Villacampa

unread,
Sep 27, 2012, 8:22:53 PM9/27/12
to rubym...@googlegroups.com
I've found this bug too, and used cocoa to get arround it:

    formatter = NSNumberFormatter.alloc.init
    formatter.setNumberStyle NSNumberFormatterDecimalStyle
    formatter.setMaximumFractionDigits 1
    formatter.setRoundingMode NSNumberFormatterRoundDown

    numberString = formatter.stringFromNumber(Value)

Eugene Alfonso

unread,
Sep 28, 2012, 11:20:33 AM9/28/12
to rubym...@googlegroups.com
You can use this as well:

'%.2f' % 2.3345

Bodacious

unread,
Feb 19, 2013, 10:59:29 AM2/19/13
to rubym...@googlegroups.com
I'm experiencing this issue in the latest version of RM

Did you file a bug report?

Joffrey Jaffeux

unread,
Feb 20, 2013, 4:11:46 AM2/20/13
to rubym...@googlegroups.com
Hi,

yes it's a known bug you can find the issue in the RubyMotion's tracker : http://hipbyte.myjetbrains.com/youtrack/issue/RM-4
Reply all
Reply to author
Forward
0 new messages