在本文中,我们将给您介绍关于输入时在Swift中的文本字段中设置货币格式的详细内容,并且为您解答swift输入语句的相关问题,此外,我们还将为您提供关于excel怎么给某些单元格设置货币格式?exce
在本文中,我们将给您介绍关于输入时在Swift中的文本字段中设置货币格式的详细内容,并且为您解答swift输入语句的相关问题,此外,我们还将为您提供关于excel怎么给某些单元格设置货币格式?excel给单元格设置货币格式的方法、Excel设置货币格式的详细方法、Excel货币格式怎么设置 Excel设置货币格式的方法、ios – 在swift 3中为货币格式化字符串设置删除线属性文本的知识。
本文目录一览:- 输入时在Swift中的文本字段中设置货币格式(swift输入语句)
- excel怎么给某些单元格设置货币格式?excel给单元格设置货币格式的方法
- Excel设置货币格式的详细方法
- Excel货币格式怎么设置 Excel设置货币格式的方法
- ios – 在swift 3中为货币格式化字符串设置删除线属性文本
输入时在Swift中的文本字段中设置货币格式(swift输入语句)
我正在尝试在用户输入时在Swift的文本字段中格式化货币输入。
到目前为止,我只能在用户完成输入后才能成功格式化它:
@IBAction func editingEnded(sender: AnyObject) { let formatter = NSNumberFormatter() formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle formatter.locale = NSLocale(localeIdentifier: "en_US") var numberFromField = NSString(string: textField.text).doubleValue textField.text = formatter.stringFromNumber(numberFromField)}
但是,我希望在用户输入货币后立即对其进行格式化。当我尝试在TextField操作“ Edited Changed”或“ Value
Changed”上执行此操作时,我只能输入1个数字(如果输入8,则变为$ 8.00),但是一旦输入第二个数字,所有内容将变为$ 0.00,不能超出此范围。
有什么建议?我觉得这应该很容易解决,但我不太了解。
答案1
小编典典我从今天早些时候开始修改了该功能。非常适合“ en_US”和“ fr_FR”。但是,对于“
ja_JP”,用100除以创建小数是一个问题。您将需要有一个switch或if /
else语句,该语句用小数点分隔货币和用格式化程序格式化时不包含小数的货币。但是我认为这可以让您进入想要成为的空间。
import UIKitclass ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var textField: UITextField! var currentString = "" override func viewDidLoad() { super.viewDidLoad() self.textField.delegate = self } //Textfield delegates func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { // return NO to not change text switch string { case "0","1","2","3","4","5","6","7","8","9": currentString += string println(currentString) formatCurrency(string: currentString) default: var array = Array(string) var currentStringArray = Array(currentString) if array.count == 0 && currentStringArray.count != 0 { currentStringArray.removeLast() currentString = "" for character in currentStringArray { currentString += String(character) } formatCurrency(string: currentString) } } return false } func formatCurrency(#string: String) { println("format \(string)") let formatter = NSNumberFormatter() formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle formatter.locale = NSLocale(localeIdentifier: "en_US") var numberFromField = (NSString(string: currentString).doubleValue)/100 textField.text = formatter.stringFromNumber(numberFromField) println(textField.text ) }}
excel怎么给某些单元格设置货币格式?excel给单元格设置货币格式的方法
excel中怎么设置货币格式
1、首先我们找到电脑中的excel表格
@H_301_5@
2、双击打开
@H_301_5@
3、随意输入点数值便于我们使用
@H_301_5@
4、然后我们选中内容,右击选中设置 单元格格式
@H_301_5@
5、会弹出如下选框,我们选择数字, 货币 ,在右侧选一种格式,确定即
@H_301_5@
6、最后我们看到我们刚才输入的数值已经变为货币格式了
@H_301_5@
Excel设置货币格式的详细方法
遇到过excel无法正确显示货币格式的问题吗?php小编西瓜为您讲解最详细的excel货币格式设置方法,一步步引导您轻松解决此问题。
1、双击打开Excel
2、新建一个空白表格。
3、随便写点数值,方便我们做操作。
4、选中区域右键找到设置单元格格式。
5、切换到货币的选项。
6、因为国家和地区的货币符号不一样,所有这里可以查看自己需要的货币符号,找到之后点击确定。
7、最后设置成功效果如图所示。
以上就是Excel设置货币格式的详细方法的详细内容,更多请关注php中文网其它相关文章!
Excel货币格式怎么设置 Excel设置货币格式的方法
如何设置 excel 货币格式?在处理财务数据时,正确设置 excel 货币格式至关重要,它可以使您的电子表格更加易于阅读和理解。php小编柚子为大家带来详细指南,介绍如何在 microsoft excel 中轻松设置货币格式。从数字的分隔格式到符号的添加,我们将一步一步引导您完成整个过程,让您能够准确地显示财务数据。
1、首先,开启Excel表格,选择我们想要更改的表格,点击鼠标右键选择设置单元格格式。
2、然后,在数字版块中找到货币,设置货币符号,最后点击确定就可以了。
以上就是Excel货币格式怎么设置 Excel设置货币格式的方法的详细内容,更多请关注php中文网其它相关文章!
ios – 在swift 3中为货币格式化字符串设置删除线属性文本
let price = 1000.0 let currencyFormatter = NumberFormatter() currencyFormatter.numberStyle = .currency currencyFormatter.currencyCode = "INR" let priceInINR = currencyFormatter.string(from: price as NSNumber) let attributedString = NSMutableAttributedString(string: priceInINR!) attributedString.addAttribute(NsstrikethroughStyleAttributeName,value: 1,range: NSMakeRange(0,attributedString.length)) self.oldPriceLabel.attributedText = attributedString
有没有办法同时为字符串设置货币格式化程序和删除线属性?
解决方法
@IBOutlet var oldPriceLabel: UILabel! func strikeOnLabel(){ let price = 1000.0 let currencyFormatter = NumberFormatter() currencyFormatter.numberStyle = .currency currencyFormatter.currencyCode = "INR" let priceInINR = currencyFormatter.string(from: price as NSNumber) let attributedString = NSMutableAttributedString(string: priceInINR!) // Swift 4.2 and above attributedString.addAttribute(NSAttributedString.Key.strikethroughStyle,value: 2,attributedString.length)) // Swift 4.1 and below attributedString.addAttribute(NSAttributedStringKey.strikethroughStyle,attributedString.length)) oldPriceLabel.attributedText = attributedString }
结果:
₹1,000.00
对于Swift 2:
let price = 1000.0 let currencyFormatter = NumberFormatter() currencyFormatter.numberStyle = .currency currencyFormatter.currencyCode = "INR" let priceInINR = currencyFormatter.string(from: price as NSNumber) let attributedString = NSMutableAttributedString(string: priceInINR!) // Swift 4.2 and above attributedString.addAttribute(NSAttributedString.Key.strikethroughStyle,attributedString.length)) // Swift 4.1 and below attributedString.addAttribute(NsstrikethroughStyleAttributeName,attributedString.length)) self.oldPriceLabel.attributedText = attributedString
今天的关于输入时在Swift中的文本字段中设置货币格式和swift输入语句的分享已经结束,谢谢您的关注,如果想了解更多关于excel怎么给某些单元格设置货币格式?excel给单元格设置货币格式的方法、Excel设置货币格式的详细方法、Excel货币格式怎么设置 Excel设置货币格式的方法、ios – 在swift 3中为货币格式化字符串设置删除线属性文本的相关知识,请在本站进行查询。
本文标签: