---
title: "#190: Converting Units with Scale 📏📐"
url: https://littlebitesofcocoa.com/190-converting-units-with-scale
author: Jake Marsh
published: 2016-02-12
topics: ["Libraries","Foundation"]
description: "Today we'll follow up with another Bite in our localization series (sort of). Units of measurement are important to get right when localizing our apps for..."
---

# #190: Converting Units with Scale 📏📐

By Jake Marsh, February 12, 2016. HTML: https://littlebitesofcocoa.com/190-converting-units-with-scale

Today we'll follow up with another **Bite** in our [localization series](https://littlebitesofcocoa.com/topics/65-localization?v=l)<i> (sort of)</i>. Units of measurement are important to get right when localizing our **apps** for different cultures.

Today we'll look at a library from [Khoa Pham](https://github.com/onmyway133) called [Scale](https://github.com/onmyway133/Scale) that can help us convert between different units of measurement (for either localization or just-for-fun purposes). Let's begin.

[Scale](https://github.com/onmyway133/Scale) makes it incredible simple to work with different units of measurement:

``` swift
let length = 5.kilometer + 7.meter  // 5,007 meters
let weight = 10.0.kilogram * 5.gram // 50,000 grams
```

Everything is strongly-typed, and conversion is a breeze:

``` swift
2.week.to(unit: .hour) // 336 hours
```

Scale even provides nicely formatted debug output. For example, `print`'ing that last statement logs:

``` text
Time(value: 336.0, unit: Scale.TimeUnit.hour)
```

[Scale](https://github.com/onmyway133/Scale) supports a wide variety of units:

``` swift
let angle = 5.degree + 2.radian
let area = 5.acre + 2.hectare
let metric = 5.base + 2.kilo
let volume = 5.liter + 2.gallon
// + many more...
```

One more example to show off how readable Scale's API is. Here we'll add two typed units together, then convert them:

``` swift
let time = 4.day + 1.week
print(time.to(unit: .week))
```

``` text
Time(value: 1.57142857142857, unit: Scale.TimeUnit.week)
```

More info about _Scale_ can be found at [git.io/scale](http://git.io/scale)
