简体   繁体   English

本地笔尖的小数。 如何运作?

[英]Decimal in localized nib. How to get it work?

In my nib there are 3 fields displaying a decimal number from a string (initWithFormat %f). 在我的笔尖中,有3个字段显示字符串中的十进制数字(initWithFormat%f)。 When I make my nib local those fields has to display the numbers with a decimal comma instaed of a decimal point. 当我将笔尖放在本地时,这些字段必须显示带有小数点的小数点逗号的数字。 Localizition works well for the labels etc. due to a localalized (dutch) nib. 由于本地化(荷兰语)笔尖,本地化对标签等效果很好。 The decimal separator is still a point. 小数点分隔符仍然是点。

What am I overlooking? 我在俯视什么?

EDIT: I have tried the options mentioned in the answers but I'm not able to get it to work. 编辑:我已经尝试了答案中提到的选项,但我无法使其正常工作。 In my dutch localization the values still are displayd wit a decimal dot instaed of a comma. 在我的荷兰语本地化中,这些值仍显示为带有逗号的小数点。 Can you help met with for example this bit of code? 例如,您能帮忙遇到一下这段代码吗?

//display accuracy
NSString *acc = [[NSString alloc] initWithFormat:@"%f", newLocation.horizontalAccuracy];
accuracy.text=acc;

代替initWithFormat: ,例如,使用NSString类中的localizedStringWithFormat :。

One option would be to use NSNumberFormatter instead of string formats. 一种选择是使用NSNumberFormatter而不是字符串格式。 NSNumberFormatter allows you to format numbers that display properly based on the user's locale. NSNumberFormatter允许您格式化数字,以根据用户的语言环境正确显示。 You can setup the formatter for showing numbers as decimals, percents, currency, or scientific notation. 您可以设置格式化程序以将数字显示为小数,百分比,货币或科学计数法。 There are many options for specifying the number of decimal places, rounding, and many other aspects of how the number should be formatted. 有许多选项可用于指定小数位数,舍入以及应如何格式化数字的许多其他方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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