objective c - Convert double to NSNumber keeping decimal part even if there are 0s -


i download json data has inside price, price gets downloaded double example if have 10.50 value assigned variable 10.5, how can keep 0 after first decimal number?

this code used create nsnumber:

nsnumber *numprice = jsonelement[@"price"];  //the json 10.50 numprice becomes 10.5  nsnumberformatter *formatter = [[nsnumberformatter alloc] init];  [formatter setnumberstyle:nsnumberformatterdecimalstyle]; [formatter setmaximumfractiondigits:2]; [formatter setroundingmode: nsnumberformatterroundup];  nsstring *numberstring = [formatter stringfromnumber:numprice]; 

for output purposes can set nsnumberformatterto have 2 decimal digits like

[formatter setminimumfractiondigits:2]; [formatter setmaximumfractiondigits:2]; 

this displaying 2 decimal numbers. internally nsnumber stored of course single digit, if possible.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -