In app, which I am developing, I am dealing with the decimal values. I am priting them using CATextLayer. But, when we select Region German from settings of device, it does not show value after decimal point. But when US/UK/AUSTRALIA region is selected, it shows values after decimal point. Please reply if anyone has faced/worked on such issue
Asked
Active
Viewed 172 times
1
-
Can you post some code? Did you use the https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSNumberFormatter_Class/Reference/Reference.html – Michael May 30 '12 at 09:29
-
take example in (English) = 1.08 in German it will be 1,08 means in germany decimal(.) is replaced by comma(,). – Mudit Bajpai May 30 '12 at 09:29
-
@Michael: No, I am not using NSNumberFormatter. I am just setting string of CATextLayer.text is CATextLayer. [text setstring:[NSString stringWithFormat:@"%0.4g ", [EXPUtils getRoundedFloat:value]]]; Value is float in which I am storing desired value to print. – Suresh Jambhalkar May 30 '12 at 10:39
-
@mudit: u siggesting me to manually check for region and then according to it, display value??? – Suresh Jambhalkar May 30 '12 at 10:44
-
Have you debugged `[EXPUtils getRoundedFloat:value]`? Have you tried using the number formatter? – Michael May 30 '12 at 11:37
-
@SureshJambhalkar:firstly i am not saying to you do manually checking. i was just giving you the actual info about format of decimal number used in germany. check this [link](http://stackoverflow.com/a/9108196/845115)it is useful for you i think. – Mudit Bajpai May 30 '12 at 11:37
-
@Michael: Here is Definition of getRoundedFloat +(float) getRoundedFloat:(float) number{ NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setMaximumFractionDigits:3]; [formatter setRoundingMode: kCFNumberFormatterRoundHalfUp]; NSString *numberString = [formatter stringFromNumber:[NSNumber numberWithFloat:number]]; [formatter release]; return [numberString floatValue]; } If the value generated is 2.5, when german is selected, it shows 2,5 in numberString. But when I return the float value, it returns only 2. How can I solve this? – Suresh Jambhalkar May 31 '12 at 05:00
-
@Michael Thanks a lot!!! I got the solution after debugging EXPUtils :) – Suresh Jambhalkar Jun 01 '12 at 07:34
-
@SureshJambhalkar Please provide the solution here. Maybe others face the same problem in the future. (You can answer your question yourself) – Michael Jun 01 '12 at 11:18