Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Created April 18, 2019 13:27
Show Gist options
  • Save yasuabe/ec1c6266c185866e07a6ec339e5672ff to your computer and use it in GitHub Desktop.
Save yasuabe/ec1c6266c185866e07a6ec339e5672ff to your computer and use it in GitHub Desktop.
squants exercise: Money and Price
import squants.market.{JPY, MoneyContext, USD}
import squants.market.MoneyConversions._
val rate = USD / 112.14.yen
// r: CurrencyExchangeRate = USD/JPY 112.14
rate convert 10.dollars
// 1121.4 JPY
import squants.market.defaultMoneyContext
implicit val moneyContext: MoneyContext =
defaultMoneyContext withExchangeRates List(USD / 112.14.yen)
10.dollars in JPY
// 1121.4 JPY
import squants.space.VolumeConversions._
// 原油価格 1バレル(42ガロン) につき 64.39 USドル
val oilPrice = 64.39.dollars / 42.gallons
// oilPrice: Price[Volume] = 64.39 USD/42.0 gal
// これを1000リットル買うと日本円で、、、
(oilPrice * 1000.liters in JPY).toFormattedString
// res2: String = ¥45417
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment