WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Day 17 - formatting numbers in Text and TextField in custom locale

Forums > 100 Days of Swift

I've been working on the WeSplit app from days 17-18 of the course recently. I saw that that the .currency(code:) formatter is used to format numbers depending on user's locale, so I customized the locale in the preview to see if anything would change - specifically to the Polish locale, which, like most European languages I think, uses comma as the decimal separator.

Surprisingly, even though Text and TextField use exactly the same format specifier, the number in Text is printed with a comma, while the number in TextField is printed with a period, formatted in the English style.

Is there any way to make TextField use the same format, which I think would be more consistent?

This is the code I have and what I get:


Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.