<commit_before><?php
/**
 * $Id$
 *
 * Conversion functions for different currencies
 *
 * References
 * ----------
 * http://en.wikipedia.org/wiki/List_of_circulating_currencies
 * http://en.wikipedia.org/wiki/ISO_4217 (Standard currency codes)
 *
 * @author <NAME>, 2009 <<EMAIL>>
 */

require_once('service_currency_webservicex.php');

class currency
{
	/**
	 * Converts specified ammount of $from currency into $to currency
	 * @param $val the value to convert from
	 * @param $from currency code to convert from
	 * @param $to currency code to convert to
	 * @return converted currency
	 */
	function conv($from, $to, $val)
	{
		$rate = $this->rate($from, $to);
		if (!$rate) return false;
		return $val * $rate;
	}

	/**
	 * Returns the current currency conversion for specified currencies
	 * @param $from ISO 4217 currency code (USD, GBP, SEK)
	 * @param $to ISO 4217 currency code
	 */
	function rate($from, $to)
	{
		if (!$this->decode($from) || !$this->decode($to)) return false;

		return webservicex_currency_conversion_rate($from, $to);
	}<commit_msg>added precision to automatically round return<commit_after><?php
/**
 * $Id$
 *
 * Conversion functions for different currencies
 *
 * References
 * ----------
 * http://en.wikipedia.org/wiki/List_of_circulating_currencies
 * http://en.wikipedia.org/wiki/ISO_4217 (Standard currency codes)
 *
 * @author <NAME>, 2009 <<EMAIL>>
 */

require_once('service_currency_webservicex.php');

class currency
{
	var $precision = 0; ///< if set specifies how many decimals to return (rounded)

	/**
	 * Converts specified ammount of $from currency into $to currency
	 * @param $val the value to convert from
	 * @param $from currency code to convert from
	 * @param $to currency code to convert to
	 * @return converted currency
	 */
	function conv($from, $to, $val)
	{
		$rate = $this->rate($from, $to);
		if (!$rate) return false;

		if ($this->precision)
			return round($val * $rate, $this->precision);

		return $val * $rate;
	}

	/**
	 * Returns the current currency conversion for specified currencies
	 * @param $from ISO 4217 currency code (USD, GBP, SEK)
	 * @param $to ISO 4217 currency code
	 */
	function rate($from, $to)
	{
		if (!$this->decode($from) || !$this->decode($to)) return false;

		return webservicex_currency_conversion_rate($from, $to);
	}
{'fraction_non_alphanumeric': 0.14747736093143596, 'fraction_numerical': 0.014230271668822769, 'mean_word_length': 3.8637316561844863, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '644270', 'n_tokens_mistral': 794, 'n_tokens_neox': 708, 'n_words': 225}