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 returns 0 instead original value.

i tried below code:

  1. (signed)[@"-0.02" intvalue] //returns 0
  2. [[nsnumberformatter new] numberfromstring:timespent] //returns nsnumber -0.02 value while < 0 comparison, converted nsnumber 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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -