Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

411
Views
Add leading and trailing zeroes to a string/label in swift

In swift I know how to set the number of digits after the decimal point when converting a double to a string:

String(format: "%0.2f", someDouble)

Similarly I know how to set the number of digits before the decimal point:

String(format: "%02d", someDouble)

But how can I do both?

I want the string to always have a 00.00 format.

Thanks

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You simply combine the two:

String(format: "%05.2f", someDouble)

The 0 means fill with leading zeros as needed.
The 5 means you want the final output to be at least 5 characters, include the decimal point.
The .2 means you want two decimal places.

If this is a number you are showing to a user then you should probably use NumberFormatter so the decimal is properly formatted for the user's locale.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!