简体   繁体   中英

how to give comma(,) separator as decimal separator in ios 6?

In my app im using HTML page for taking the data from the user in that im taking an textfield with type number ,my problem is that after entering the number into the textfield click on done button data coming on textfield with comma (,) separator ,this one working fine in ios 5 but in ios 6 not coming ,please give a suggestion for getting comma separator in ios 6 ?

function addCommas(nStr)
        {

            nStr = removeCommas(nStr);

            nStr += '';
            x = nStr.split('.');
            x1 = x[0];
            x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }

im using above code for placing comma,

Dont try to create a custom method to handle number separator. IOS has built in methods for that and it works depending on the user Country.

You need to do something like this:

NSNumberFormatter *nf;
nf = [[NSNumberFormatter alloc] init];
[nf setMaximumFractionDigits:2]; // to show only two decimal places
NSNumber *num =[nf numberFromString:@"123456.789"];
NSLog([nf stringFromNumber:num]);

Check apple's doc for NSNumberFormatter , for more info and options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM