Skip to content

Instantly share code, notes, and snippets.

@kinncj
Last active June 6, 2017 13:54
Show Gist options
  • Save kinncj/80c280f04db56b04b627 to your computer and use it in GitHub Desktop.
Save kinncj/80c280f04db56b04b627 to your computer and use it in GitHub Desktop.
Dilmas Currency
<?php
class Dilmas extends \SplFloat
{
public function __construct($value)
{
$currency = json_decode(file_get_contents('http://api.fixer.io/latest?base=USD&symbols=BRL'), true);
$brl =(float) $currency['rates']['BRL'];
parent::__construct(((float) round($value / $brl, 2)));
}
}
<?php
require_once 'Dilmas.php';
$value1 = new Dilmas(10);
$value2 = new \SplFloat(2);
echo bcadd($value1, $value2, 2); // return depends on currency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment