in C# (int) decimal and Convert.Int32(decimal) give me two different results
By : yongbam
Date : March 29 2020, 07:55 AM
help you fix your problem I understand that there are rounding errors but can anyone explain why I get such different results using these different methods: , The second one should be code :
var cost1 = (int)(amount * 1000);

Limit Text Field to one decimal point input, numbers only, and two characters after the decimal place  Swift 3
By : Thomas.Nicolas.Pangz
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: code :
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)
}

python 3  rounding a Decimal with negative ndigits results in Decimal with scientific notation
By : Sahil
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , This is normal and intended. Decimal tracks significant digits, and the Decimal repr is intended to preserve significant digits. Decimal('3.3E+3') has two significant digits, while Decimal('3300') has four.

Regular expression for length limit 10 digit before decimal till 2 decimal place with Number only?
By : bodzio2k
Date : March 29 2020, 07:55 AM
hop of those help? You're almost there  all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .{1,10} right after the ^), and check that its first digit string has at most 10 characters (just use a {0,10} quantifier for the digits). Also note that [09] simplifies to \d. In order to also exclude trailing dots, repeat the digit after the dot with {1,2} instead of {0,2}: code :
^(?!$)\d{0,10}(?:\.\d{1,2})?$

Limit PowerShell VersionInfo output to only 3 decimal places where 4 decimal places are given or Remove Decimal Place in
By : Mr Anonymous
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I tried my best to find the answer on my own for almost 2 days before posting. I apologize in advance if this question is already answered somewhere on this site. , Try this:

