ios - NSString to NSNumber ignores initial zeros -
i converting nsstring
nsnumber
. problem if nsstring
starts zeros converting nsnumber
ignores initial zeros. know initial zeros doesn't mean want keep initial zeros because it's phonenumber in case.
here code:
nslog(@"test1: %@",tempphonenumber); nsnumberformatter *formatter=[[nsnumberformatter alloc] init]; [formatter setnumberstyle:nsnumberformatterdecimalstyle]; nsnumber *temppnonenumbernumber=[formatter numberfromstring:tempphonenumber]; nslog(@"test: %@",temppnonenumbernumber);
if test1: 00966123456789 test: 966123456789
i want both same
nsnumber
cannot keep initial zeros.
if want keep zeros, don't convert it nsnumber
. phone numbers not numbers, there kept strings.
also note phonenumbers can contain other characters: +
, *
or #
. these characters have special meaning (e.g. +
@ beginning means same 00
).
Comments
Post a Comment