Advertisement
pcwizz

Untitled

Feb 9th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.56 KB | None | 0 0
  1. func CurrencyExchangeHandler(/*irccon *irc.Connection,*/ value string)(){
  2.     var code string
  3.     //Work out currency
  4.     switch{
  5.         case strings.HasPrefix(value, "$"):
  6.             code = "USD"
  7.             value = strings.TrimPrefix(value, "$")
  8.         case strings.HasPrefix(value, "£"):
  9.             code = "GBP"
  10.             value = strings.TrimPrefix(value, "£")
  11.         case strings.HasPrefix(value, "€"):
  12.             code = "EUR"
  13.             value = strings.TrimPrefix(value, "€")
  14.         case strings.HasPrefix(value, "Fr."):
  15.             code = "CHF"
  16.             value = strings.TrimPrefix(value, "Fr.")
  17.         case strings.HasPrefix(value, "SFr."):
  18.             code = "CHF"
  19.             value = strings.TrimPrefix(value, "SFr.")
  20.         case strings.HasPrefix(value, "FS"):
  21.             code = "CHF"
  22.             value = strings.TrimPrefix(value, "FS")
  23.     }  
  24.     if code == "" {
  25.         log.Fatal(errors.New("Currency not recognised"))
  26.     }  
  27.     value = strings.Trim(value, " ")//trim white space
  28.     value_flt, err := str_to_flt(value)
  29.     USD, err := ConvertCurrency(code, "USD", value_flt)
  30.     if err != nil {
  31.         log.Fatal(err)
  32.     }  
  33.     GBP, err := ConvertCurrency(code, "GBP", value_flt)
  34.     if err != nil {
  35.         log.Fatal(err)
  36.     }  
  37.     EUR, err := ConvertCurrency(code, "EUR", value_flt)
  38.     if err != nil {
  39.         log.Fatal(err)
  40.     }  
  41.     CHF, err := ConvertCurrency(code, "CHF", value_flt)
  42.     if err != nil {
  43.         log.Fatal(err)
  44.     }
  45.     fmt.Printf("$%v\t£%v\t€%v\tFS%v\n", USD, GBP, EUR, CHF)
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement