ios - How to convert NSString with negative integer into negative integer -
in app, want display 0
if nsstring contains negative integers. tried convert nsstring signed int nsstring signed int conversion code returns 0
value.
eg: want convert
@"-0.02"
-0.02 int
. code returns0
instead original value.
i tried below code:
(signed)[@"-0.02" intvalue]
//returns 0[[nsnumberformatter new] numberfromstring:timespent]
//returns nsnumber -0.02 value while< 0
comparison, convertednsnumber
signedintvalue
(signed)[[[nsnumberformatter new] numberfromstring:timespent] intvalue]
//but returns 0
anyone knows how in ios - objective-c?
you have use double
instead of int
you string value double
not integer
.
nsstring *numberstring = @"-0.02"; double value = [numberstring doublevalue]; nslog(@"%.2f", value); //-0.02
Comments
Post a Comment