PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 10, 2022

[FIXED] How can a decimal number with a comma be converted in a decimal (Point) in SwiftUI?

 August 10, 2022     calculation, decimal, formatting, swiftui     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing