-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jr-cologne/jr_trailing-zeros
Remove trailing zeros from numbers
- Loading branch information
Showing
10 changed files
with
40 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
@@ -108,14 +108,41 @@ protected function getDataset() : array { | |
protected function formatData() { | ||
$this->dataset = array_map(function (array $data) { | ||
if (isset($data['rank'], $data['symbol'], $data['name'], $data['price_usd'], $data['price_btc'], $data['percent_change_1h'])) { | ||
$data['price_usd'] = number_format($data['price_usd'], 2); | ||
$data['price_btc'] = number_format($data['price_btc'], 6); | ||
return "#{$data['rank']} {$data['symbol']} ({$data['name']}): {$data['price_usd']} USD | {$data['price_btc']} BTC | {$data['percent_change_1h']}% 1h"; | ||
$data['price_usd'] = $this->removeTrailingZeros(number_format($data['price_usd'], 2)); | ||
$data['price_btc'] = $this->removeTrailingZeros(number_format($data['price_btc'], 6)); | ||
|
||
return "#{$data['rank']} #{$data['symbol']} (#{$data['name']}): {$data['price_usd']} USD | {$data['price_btc']} BTC | {$data['percent_change_1h']}% 1h"; | ||
} | ||
|
||
throw new CryptoStatusException('Crypto data is missing', 1); | ||
}, $this->dataset); | ||
} | ||
|
||
/** | ||
* Remove trailing zeros after decimal point from number | ||
* | ||
* @param string $number | ||
* @return string | ||
*/ | ||
protected function removeTrailingZeros(string $number) : string { | ||
$number_arr = array_reverse(str_split($number)); | ||
|
||
foreach ($number_arr as $key => $value) { | ||
if (is_numeric($value) && $value == 0) { | ||
unset($number_arr[$key]); | ||
} else { | ||
if (!is_numeric($value)) { | ||
unset($number_arr[$key]); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
$number = implode(array_reverse($number_arr)); | ||
|
||
return $number; | ||
} | ||
|
||
/** | ||
* Create the Tweets with Crypto data and return them as an array | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* @author JR Cologne <[email protected]> | ||
* @copyright 2018 JR Cologne | ||
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT | ||
* @version v0.1 | ||
* @version v0.1.2 | ||
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository | ||
* | ||
* ________________________________________________________________________________ | ||
|