Issue
How can a textField were a comma is inserted be Formated so the inserted Decimal value example 10,05$ can be converted to a decimal(Point) 10.05$?
private static let Intrest = "Intrest"
private static let Repayment = "Repayment"
var loan: Double {
    let intrest = Double (Intrest)
    let repayment = Double (Repayment)
    let Loan = Intrest + Repayment
    return Loan
}
var body: some View {
     VStack{
        HStack{
           Text ("Repayment %")
           Spacer()
           TextField("2 %", text: $Repayment)
                .keyboardType(.decimalPad)
            }
      VStack{
         HStack{
            Text ("Loan / month")
            }
            TextField("2 %", text: $Loan)
                .keyboardType(.decimalPad)
            }
}
The problem only occurs because in many countries mostly comma is used which breaks the calculation.
Thanks
Solution
You need to make sure you convert your string into a double with point and not comma.
This one should help. Swift playground - How to convert a string with comma to a string with decimal
Answered By - Volker88 Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.