Hi
I am loosing precision of a number somewhere in my code, the number is a price in a pricelist I have in a DB, the workflow is as follows
The App requests the price from a webservice that responds with a JSON object, when I dump the JSON object in my app using NSLog I can see the precision being correct 6.95 in this case
I then use this value and insert it in a Local SQLite DB using the following command
NSString *query = [NSString stringWithFormat:@"insert into prl (currencyName, price, priceIncTAX, validFrom, validTo, itemId) values('%@', %d, %d, '%@', '%@', '%@')", currencyName, [price intValue], [priceIncTAX intValue], validFrom, validTo, itemId];
If I look at the price variable using NSLog like below I can see the correct precision of 6.95
NSLog(@"Price for this item = %@", price);
The price variable comes from the JSON ibject like below
NSString *price = [priceListObject objectForKey:@"Price"];
So far everything looks ok, every NSLog output shows correctly 6.95
Now I try and select from the DB as follows
/
NSString *query = [NSString stringWithFormat:@"select tilldata.itemId, tilldata.TradeItemDesc, prl.price from tilldata JOIN prl ON tilldata.itemId = prl.itemId where noos14 like '%%%@%%'", barCode];
NSLog(@"Query looks like:%@", query);
/
NSArray *items = [[NSArray alloc] initWithArray:[self.dbManager loadDataFromDB:query]];
NSLog(@"Items array holds: %@", items);
Now all of a sudden the items array has the price as 6 and not 6.95
I am assuming I am using NSString incorrectly somehow in all of this but I cannot figure out a way to keep the precision throughout the code
Any ideas would be very helpful