// Convert foreign currency to NPR.
Convert foreign currency to NPR.
// Convert foreign currency to NPR .
func convert(c *cli.Context) {
	amount := c.Args().Get(0)
	currency := c.Args().Get(1)
	amount = getAmount(amount)
	currency = getCurrency(currency)
	amt, err := strconv.ParseFloat(amount, 64)
	if err != nil {
		fmt.Printf("Please input a valid number for amount.\n")
		os.Exit(1)
	}
	currency = strings.ToUpper(currency)
	rates := fetchExchangeRate()
	selectedCurrency := getSelectedCurrency(rates, currency)
	if (selectedCurrency == Currency{}) {
		fmt.Println("Could not find the currency you are looking for.\nRun 'forex l' to view all the available currencies.")
		os.Exit(1)
	}
	if selectedCurrency.TargetBuy == "" {
		fmt.Printf("Cannot get the rates for %s. Looks like the buying rate is empty.\nUse 'forex l' to list buying rates of all available currencies.\n", currency)
		os.Exit(1)
	}
	unitRate := getUnitRate(selectedCurrency)
	buyingValue := amt * unitRate
	fmt.Printf("%.2f %s -> %.2f NPR\n", amt, currency, buyingValue)
}
func convert ( c * cli . Context ) { amount := c . Args ( ) . Get ( 0 ) currency := c . Args ( ) . Get ( 1 ) amount = getAmount ( amount ) currency = getCurrency ( currency ) amt , err := strconv . ParseFloat ( amount , 64 ) if err != nil { fmt . Printf ( " \n " ) os . Exit ( 1 ) } currency = strings . ToUpper ( currency ) rates := fetchExchangeRate ( ) selectedCurrency := getSelectedCurrency ( rates , currency ) if ( selectedCurrency == Currency { } ) { fmt . Println ( " \n " ) os . Exit ( 1 ) } if selectedCurrency . TargetBuy == " " { fmt . Printf ( " \n \n " , currency ) os . Exit ( 1 ) } unitRate := getUnitRate ( selectedCurrency ) buyingValue := amt * unitRate fmt . Printf ( " \n " , amt , currency , buyingValue ) }
Convert foreign currency to NPR.
Convert foreign currency to NPR .