nsnumberformatter

Can't get UITextField to populate when using .currency format of NumberFormatter()

牧云@^-^@ 提交于 2019-12-13 02:59:11
问题 I borrowed and modified some code from SO to solve a problem where I was trying to format text that I inputted into my UITextField s. If I use the .decimal numberStyle of NumberFormatter it works (adds a comma where I need it) but if I use .currency I can't type anything once I run the app. The UITextField will not populate. I've tried playing around with the locale and that doesn't seem to solve anything. All I want to do is to show the user the "$" sign in front of the number they type as

Swift: NSTextField numberStyle not calling action

余生颓废 提交于 2019-12-12 04:26:16
问题 I have a NSTextField that I have setup with the following code: func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? { let cell : NSTableCellView? = tableView.makeViewWithIdentifier("AutomaticTableColumnIdentifier.0", owner: self) as! NSTableCellView? cell!.textField!.floatValue = 4.55 let numberFormatter = NSNumberFormatter() numberFormatter.numberStyle = .CurrencyStyle numberFormatter.maximumFractionDigits = 0 cell!.textField! =

Display superscript % using NSNumberFormatter

不问归期 提交于 2019-12-11 17:33:22
问题 I'm using an NSNumberFormatter to display a percentage: NSNumberFormatter *inclineFormat = [[[NSNumberFormatter alloc] init] autorelease]; [inclineFormat setMinimumFractionDigits:1]; [inclineFormat setNumberStyle:NSNumberFormatterPercentStyle]; It's working as expected with the exception that the design team would like to see the "%" in superscript. Is there anyway to specify that using NSNumberFormatter? I'm displaying the formatted string in a UILabel in iOS devices. 回答1: % does not exist

Having trouble using NSNumberFormatter for currency conversion in iOS

好久不见. 提交于 2019-12-11 16:36:59
问题 I have a UITextField that receives numeric input from the user in my application. The values from this textfield then get converted into currency format using NSNumberFormatter within my shouldChangeCharactersInRange delegate method. When I enter the number "12345678", the number gets correctly converted to $123456.78 (the numbers are entered one digit at a time, and up to this point, everything works smoothly). However, when I enter another digit after this (e.g. 9), rather than displaying

How to pad the integer withe preceeding 0?

£可爱£侵袭症+ 提交于 2019-12-11 13:38:13
问题 I am having an integer value like 6 or 65 . If the value is single digit I want to display it like 06 and if it is 65 then as it is ( 65 only ) . I have searched into the NSNumberFormatter class of iphone but not getting what to do exactly . Can any one help me in this ? Thanks in advance !! 回答1: Use %02d format specifier, e.g. NSLog(@"%02d", number); That will output integer number with at least 2 characters length and output will be padded with leading zeroes if required 回答2: For using the

NSNumberFormatter Currency displayed differently in iOS 5.1 and 6.x

我只是一个虾纸丫 提交于 2019-12-11 08:27:49
问题 I'm currently developing an app that has to display currencies dependant on a certain culture, my code is: NSLocale* myLocale= [[NSLocale alloc] initWithLocaleIdentifier:myCurrency]; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [formatter setLocale:myLocale]; [formatter setGroupingSize:3]; [formatter setAlwaysShowsDecimalSeparator:NO]; [formatter setUsesGroupingSeparator:YES]; NSString *formattedString = [formatter

NSNumberFormatter numberFromString decimal number

依然范特西╮ 提交于 2019-12-11 03:04:17
问题 I'm trying to parse a NSString with a NSNumberFormatter like following. NSNumberFormatter *myFormatter = [[[NSNumberFormatter alloc] init]; NSNumber *myNumber = [myFormatter numberFromString:@"42.00000"]; numberFromString returns a NSNumber object in the simulator but not on a device. The decimals (.00000) are causing the return value to be nil on a device because parsing 42 (without the decimals) works just fine (both in the simulator and on a device). The reason I'm using a

NSNumberFormatter paddingPosition doesn't work

家住魔仙堡 提交于 2019-12-10 16:35:29
问题 I have a formatted currency value like this. $99.99 . I need to have a space in between the currency symbol and the amount like so $ 99.99 . From this answer I found that I need to use padding for this. However what I'm trying isn't working. private var currencyFormatter: NSNumberFormatter = { let formatter = NSNumberFormatter() formatter.numberStyle = .CurrencyStyle formatter.paddingPosition = .AfterPrefix return formatter }() var price: Float = 99.99 let s = currencyFormatter

Singleton and NSNumberFormatter in Swift

隐身守侯 提交于 2019-12-10 10:21:09
问题 Currently, I have the following code in one of my methods: let formatter = NSNumberFormatter() formatter.numberStyle = .DecimalStyle formatter.currencyGroupingSeparator? formatter.minimumFractionDigits = 2 Because I have to repeat these in various functions in different view controllers, how do I create a singleton in Swift to call for the NSNumberFormatter and avoid duplicates? I assume that I have to create a new Swift file, but unsure of how to construct the class? 回答1: update: Xcode 8.2.1

NSNumberFormatter doesn't allow typing decimal numbers

混江龙づ霸主 提交于 2019-12-08 15:59:00
问题 I am totally bewildered using NSNumberFormatter. This should be totally simple but I can't get it to work. I'd like to set an NSTextField to allow typing decimal numbers, either with a decimal point or without. Here is what I'd think would work: NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; [formatter setMinimumFractionDigits:0]; [formatter setMaximumFractionDigits:4]; [formatter setAllowsFloats:YES]; [