Iphone keyboard with numbers, decimal point and minus sign
Tag : iphone , By : user181706
Date : March 29 2020, 07:55 AM
this one helps. No. What you can do is use the UIKeyboardTypeDecimalPad keyboard type to get the numbers and decimal point.
|
How to multiply decimal numbers without using multiplication(*) sign
Tag : chash , By : Atanas
Date : March 29 2020, 07:55 AM
With these it helps Bit of a cheat, but if the task strictly relates to all forms of multiplication (rather than just the * operator), then divide by the reciprocal: var result = first / (1 / (decimal)second);
|
Locale aware edit control subclassing for decimal numbers ( format [sign] [xxx...] [decimal separator] [yy...] )
Tag : cpp , By : James Dio
Date : March 29 2020, 07:55 AM
hope this fix your issue Taking into consideration locale-specific settings You certainly can do everything yourself, however you have an option to use VarI4FromStr or similar API which does dirty stuff for you. You put string in, you get LONG out. Locale aware.
|
Limit Text Field to one decimal point input, numbers only, and two characters after the decimal place - Swift 3
Tag : ios , By : cheese_doodle
Date : March 29 2020, 07:55 AM
this will help You need to assign delegate to your textfield and in the shouldChangeCharactersIn delegate method do your validations: extension String{
private static let decimalFormatter:NumberFormatter = {
let formatter = NumberFormatter()
formatter.allowsFloats = true
return formatter
}()
private var decimalSeparator:String{
return String.decimalFormatter.decimalSeparator ?? "."
}
func isValidDecimal(maximumFractionDigits:Int)->Bool{
// Depends on you if you consider empty string as valid number
guard self.isEmpty == false else {
return true
}
// Check if valid decimal
if let _ = String.decimalFormatter.number(from: self){
// Get fraction digits part using separator
let numberComponents = self.components(separatedBy: decimalSeparator)
let fractionDigits = numberComponents.count == 2 ? numberComponents.last ?? "" : ""
return fractionDigits.characters.count <= maximumFractionDigits
}
return false
}
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// Get text
let currentText = textField.text ?? ""
let replacementText = (currentText as NSString).replacingCharacters(in: range, with: string)
// Validate
return replacementText.isValidDecimal(maximumFractionDigits: 2)
}
|
Remove all special characters except numbers and decimal points in ruby
Date : March 29 2020, 07:55 AM
Hope that helps Normally, a special character would be anything other than alphanumeric characters. If your own definition is the same then you need a regex to capture decimal numbers to save them from being removed: (\d\.\d)|[^a-zA-Z\d]
re = /(\d\.\d)|[^a-zA-Z\d]/
str = 'test1.3eb@j$2.xyz.'
subst = '\\1'
result = str.gsub(re, subst)
puts result
|