2011-09-30 14 views

risposta

3

NSString di: - (float)floatValue;

Ad esempio:

NSString *str = @"3.45"; 
float f = [str floatValue]; 
52
NSString *val = @"3.45"; 
float fCost = [val floatValue]; 
+0

Ok Grazie Marek Sebera – user891268

+0

Come faccio a convertire @ "3.4.5" a stare a galla, in fondo ho bisogno di confrontare carri con più punti come 1.1.2> 1.1.1 –

+0

Syed: vedere questo QA http : //stackoverflow.com/q/7848766/492624 –

4

Leggendo il commento alla risposta di Marek sembra che la stringa = realtà @"$3.45"

Per convertire che a un uso del galleggiante:

NSNumberFormatter * formatter = [[[NSNumberFormatter alloc] init] autorelease]; 
formatter.numberStyle = NSNumberFormatterCurrencyStyle; 
formatter.currencyCode = @"USD"; 

float value = [[formatter numberFromString: @"$3.45"] floatValue]; 
8
float number = [string floatValue];