[MacRuby-devel] [MacRuby] #473: setObjectValue does not set floats, integers in NSTextFields properly.
MacRuby
ruby-noreply at macosforge.org
Tue Dec 1 06:08:41 PST 2009
#473: setObjectValue does not set floats, integers in NSTextFields properly.
-----------------------------------+----------------------------------------
Reporter: johnmacshea@… | Owner: lsansonetti@…
Type: defect | Status: new
Priority: major | Milestone:
Component: MacRuby | Keywords: NSTextField, setObjectValue
-----------------------------------+----------------------------------------
When using setObjectValue (NSControl) with MacRuby floats and integer,
though they are a subclass of NSNumber,they are not properly set
(copied?).
For example in macirb:
irb(main):001:0> framework "Cocoa"
=> true
irb(main):002:0> tf = NSTextField.alloc.init
=> #<NSTextField:0x20024b5a0>
irb(main):003:0> num = NSNumber.numberWithFloat(23.3)
=> 23.2999992370605
irb(main):004:0> tf.setObjectValue(num)
=> #<NSTextField:0x20024b5a0>
irb(main):005:0> p tf.stringValue
"0"
=> "0"
irb(main):006:0> p num.superclass.superclass
NSNumber
=> NSNumber
irb(main):007:0> tf.setFloatValue(23.3)
=> #<NSTextField:0x20024b5a0>
irb(main):008:0> p tf.stringValue
"23.29999923706055"
=> "23.29999923706055"
or, more simply:
irb(main):013:0> tf.setObjectValue(23.3)
=> #<NSTextField:0x20024b5a0>
irb(main):014:0> p tf.stringValue
"0"
=> "0"
To contrast with proper behavior, with the following obj C code:
NSTextField *tf = [[NSTextField alloc] init];
NSNumber *num = [NSNumber numberWithFloat:23.3];
[tf setObjectValue:num];
NSLog(@"string value of tf %@", [tf stringValue]);
results in the following:
2009-12-01 14:48:56.553 TextFieldSet[12012:a0f] string value of tf 23.3
--
Ticket URL: <http://www.macruby.org/trac/ticket/473>
MacRuby <http://macruby.org/>
More information about the MacRuby-devel
mailing list