nsnumber

NSNumber stringValue different from NSNumber value

安稳与你 提交于 2019-12-03 09:02:59
I'm having problems with converting NSNumber to string and string to NSNumber . Here's a sample problem: NSString *stringValue = @"9.2"; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; NSLog(@"stringvalue:%@",[[formatter numberFromString: stringValue] stringValue]); Output will be: stringvalue:9.199999999999999 I need to retrieve the original value, where, in the example should be 9.2 . On the contrary, when the original string is 9.4 the output is still 9.4 . Do you have any idea how to retrieve the original string value without NSNumber doing anything about it? You are

check if NSNumber is empty

跟風遠走 提交于 2019-12-03 04:58:44
How do I check if a NSNumber object is nil or empty? OK nil is easy: NSNumber *myNumber; if (myNumber == nil) doSomething But if the object has been created, but there is no value in it because an assignment failed, how can I check this? Use something like this? if ([myNumber intValue]==0) doSomething Is there a general method for testing objects on emptiness like for NSString available (see this post )? Example 1 NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setValue:@"" forKey:@"emptyValue"]; NSNumber *emptyNumber = [dict objectForKey:@"emptyValue"]; Which value does

NSNumber gives wrong int value

◇◆丶佛笑我妖孽 提交于 2019-12-02 12:18:02
问题 I have a program that gets cookies. One param of this cookie is an NSNumber. So I save it to database as sqlite3_bind_int(addStmt, 2, HEREisNSNUMBER); Saving this value as: cookieObj.created = [paramsDictionary valueForKey:@"Created"]; then I create and object of class, and get this parameter into NSNumber; after that, I have a wrong value. For example: In cookie I have a 329822675 after saving this changes to 79931776 . How can I correctly save that number? 回答1: Please try sqlite3_bind_int

Set Precision for NSNumber value

蓝咒 提交于 2019-12-02 06:53:37
问题 I am having an issue with an NSNumber variable "num" that is currently containing 0.522000003606 I looked up several other issues on stackoverflow with others having the same issue but nothing. My project is currently using ARC so I think some features are unavailable, that is, unless I disallow ARC within the class I am currently wanting to set the precision of the NSNumber. I understand NSNumberFormatter is the basic setPrecision class function I must use but I am having issues....

Set Precision for NSNumber value

不羁岁月 提交于 2019-12-02 06:36:41
I am having an issue with an NSNumber variable "num" that is currently containing 0.522000003606 I looked up several other issues on stackoverflow with others having the same issue but nothing. My project is currently using ARC so I think some features are unavailable, that is, unless I disallow ARC within the class I am currently wanting to set the precision of the NSNumber. I understand NSNumberFormatter is the basic setPrecision class function I must use but I am having issues.... Everytime i use NSNumberFormatter, it spits back NULL!!! nowValue = [now objectForKey:@"value"]; // This is

Does NSNumberFormatter.stringFromNumber ever return nil?

送分小仙女□ 提交于 2019-12-01 16:25:10
It seems to me that any valid number can also be expressed as a String , so I don't know why this function returns a String? instead of a String . My best guess would be because of the legacy support. This is from the official documentation: The behavior of an NSNumberFormatter object can conform either to the range of behaviors existing prior to OS X v10.4 or to the range of behavior since that release. NSNumberFormatter Class Reference 来源: https://stackoverflow.com/questions/28103113/does-nsnumberformatter-stringfromnumber-ever-return-nil

How to convert NSNumber objects for computational purposes?

允我心安 提交于 2019-12-01 02:50:54
I an developing some code in which I use a scanner to get to NSNumbers from a string, say x and y. Now I want to compute something simple from x and y, say, z = 10.0/(x + y/60.0)/60.0). I can't do this directly, since the compiler doesn't like ordinary arithmetic symbology applied to number objects. So, I tried defining xD and yD, of type double, and then tried a type conversion xD = (double) x; yD = (double) y; but that also gives a compile error. Just how does one get NSNumber objects converted to be used in ordinary arithmetic expressions? I did considerable browsing of the literature, and

Xcode debugging: View value of NSNumber?

扶醉桌前 提交于 2019-12-01 01:32:46
Is it possible to see the numeric value of an NSNumber in the debugger datatip on in the variable watch window? I store an Integer value in NSNumber and want to see this value during debugging. I tried some of the data formatters in the debugger already, but it wasn't much help. Open the Debugger view and in the Summary column enter {(int)[$VAR intValue]} or whatever interpretation is most appropriate for what you want to see in the Debugger. 来源: https://stackoverflow.com/questions/753153/xcode-debugging-view-value-of-nsnumber

Adding Integer To NSMutableArray

醉酒当歌 提交于 2019-11-30 22:34:45
问题 I couldn't find this anywhere, so I am asking just asking to make sure. And yes, I know its basic, but I figure I'd rather get that right before I make the mistake a million times: If I do the following, does it cast the "0" to an NSNumber by default (if not, what Object type is it), or would I have to do the 2nd code? (Or both of these could be wrong for what I'm trying to do. If so, let me know. They both compile so I am just wondering which one is "right" (or preferred) and why.) Code 1:

How to check for null value in NSNumber

空扰寡人 提交于 2019-11-30 17:14:27
问题 First off I confess my ignorance, I've learned everything I know about Objective-C in the few months I've been working on my project. I also find it utterly frustrating how Objective-C seems to complicate what would be simple matters in any other language I've worked with. This question is a case in point... In the first run my app downloads a bunch of JSON which it uses to populate a CoreData store. I use an Obj-C/JSON library (CJSONDeserializer) to convert the JSON to NSArrays. In the JSON