Archived
1
0
Fork 0

Add USD currency to price format on Twitter

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-02-28 15:33:59 +01:00
parent 2afd36584b
commit 0902b13705
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
2 changed files with 31 additions and 5 deletions

View file

@ -90,16 +90,18 @@ func (c *TwitterNotifier) buildHashtags(productName string) string {
return ""
}
// replace price currency by its symbol
// formatPrice using internationalization rules
// euro sign is placed after the value
// default the currency, or symbol if applicable, is placed before the value
func formatPrice(value float64, currency string) string {
var symbol string
switch {
case currency == "EUR":
symbol = "€"
return fmt.Sprintf("%.2f€", value)
case currency == "USD":
return fmt.Sprintf("$%.2f", value)
default:
symbol = currency
return fmt.Sprintf("%s%.2f", currency, value)
}
return fmt.Sprintf("%.2f%s", value, symbol)
}
// NotifyWhenAvailable create a Twitter status for announcing that a product is available