---
title: "Discussion on \"Convert-As-You-Type Currency Conversion in Swift: Decimal Maths, Cached Rates and Locale-Aware Formatting\" | Hashnode"
description: "Discussion on \"Convert-As-You-Type Currency Conversion in Swift: Decimal Maths, Cached Rates and Locale-Aware Formatting\". Why Double is the wrong type for money, how to derive any cross rate from one base, keeping rates fresh without a refresh button, and formatting 150+ currencies correctly\n\nA currency converter is used"
url: "https://hashnode.com/posts/convert-as-you-type-currency-conversion-in-swift-decimal-maths-cached-rates-and-locale-aware-formatting/6ad9ed628007eb0670b9e38f"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Convert-As-You-Type Currency Conversion in Swift: Decimal Maths, Cached Rates and Locale-Aware Formatting](https://aryansbtloe.hashnode.dev/convert-as-you-type-currency-conversion-in-swift-decimal-maths-cached-rates-and-locale-aware-formatting?utm_source=hashnode&utm_medium=feed)

Why Double is the wrong type for money, how to derive any cross rate from one base, keeping rates fresh without a refresh button, and formatting 150+ currencies correctly A currency converter is used

Oct 22 · 11 min read · aryansbtloe.hashnode.dev  
Read the article

-   [#swift](https://hashnode.com/tag/swift)
-   [#ios](https://hashnode.com/tag/ios)
-   [#currency](https://hashnode.com/tag/currency)
-   [#mobile-development](https://hashnode.com/tag/mobile-development)

## Written by

[Alok Singh](https://hashnode.com/@aryansbtloe)

@aryansbtloe

  
[View profile](https://hashnode.com/@aryansbtloe)

## Responses 1

Markdown supported · ⌘↵ to post

[Furqan Ashraf](https://hashnode.com/@jfreaks)

[Oct 29](https://hashnode.com/posts/convert-as-you-type-currency-conversion-in-swift-decimal-maths-cached-rates-and-locale-aware-formatting/6ad9ed628007eb0670b9e38f/comment/6ae33239d0fac7da4ea85c35)

I'd stick with Decimal like you did. Minor units make sense once you're storing or charging money, but a rate needs a lot more precision than cents, so for a converter Decimal keeps things simpler.

One thing I noticed in RateStore: the one-hour check is based on when the phone fetched the table, not when the rates were published. If your provider only updates once a day, the app could say "updated 2 minutes ago" while showing yesterday's rates. Most APIs send a date with the response, so I'd show that instead.

Also, if the app calls the provider directly, the API key ends up inside the app and every install eats into your quota. A small proxy that fetches once an hour and caches it for everyone avoids both.

Full disclosure, I work on CurrencyFreaks, so take this with that in mind. It returns rates as strings, so your string-to-Decimal parsing works without changes, and USD is the default base, which matches your RateTable. The free plan only updates once a day though (1,000 calls a month), so your hourly refresh would only make sense on the $9.99 plan, which updates hourly. Docs if you want to compare: [https://currencyfreaks.com/documentation](https://currencyfreaks.com/documentation)

If daily rates are fine for you, Frankfurter is free and doesn't need a key, so that's an easy option too.
