<?php
namespace App\Utils\BaseParser\Structure\StructureParser\Structures\Base;

/**
 * Price parser structure
 * @author Lucian Sirbu
 */
abstract class Price extends \App\Utils\BaseParser\Structure\StructureParser\Structures\Base\Base
{
	/**
	 * Compare float numbers, return true if equal
	 * @param float $price1
	 * @param float $price2
	 * @return boolean
	 */
	protected function floatsAreEqual($price1, $price2)
	{
		return (sprintf("%.2f", $price1)===sprintf("%.2f", $price2));
	}

	/**
	 * Check if a number is equal to 0
	 * @return boolean
	 */
	protected function floatIsZero($price)
	{
		return abs($price)<0.0001;
	}

	/**
	 * Check if a float number is negative
	 * @param float $price
	 * @return boolean
	 */
	protected function floatIsNegative($price)
	{
		return $price<0.0001;
	}

	/**
	 * Check if a float number is positive
	 * @param float $price
	 * @return bool
	 */
	protected function floatIsPositive($price)
	{
		return $price>0.0001;
	}

	/**
	 * Invert the sign of a float number
	 * @param float $price
	 * @return float
	 */
	protected function floatInvert($price)
	{
		return 0.00 - $price;
	}

	/**
	 * Ceil a number to a certain number of digits
	 * @param float $number
	 * @param int $decimals
	 * @return float
	 */
	protected function ceilToPrecision($number, $decimals)
	{
		return ceil($number * pow(10, $decimals))/pow(10, $decimals);
	}

	/**
	 * Floor a number to a certain number of digits
	 * @param float $number
	 * @param int $decimals
	 * @return float
	 */
	protected function floorToPrecision($number, $decimals)
	{
		return floor($number * pow(10, $decimals))/pow(10, $decimals);
	}

	/**
	 * Round a number to a certain number of digits
	 * @param float $number
	 * @param int $decimals
	 * @return float
	 */
	protected function roundToPrecision($number, $decimals)
	{
		return round($number, $decimals);
	}

}
