Last active
January 30, 2016 17:02
-
-
Save rmrevin/32bf0de1103a2dc673a6 to your computer and use it in GitHub Desktop.
Money formatter helper
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
<?php | |
class Money | |
{ | |
/** | |
* @param string $value | |
* @return integer | |
*/ | |
public static function convertToStore($value) | |
{ | |
$value = str_replace(',', '.', $value); | |
$value = preg_replace('/\s+/', '', $value); | |
$value = preg_replace('/\x{00a0}/siu', '', $value); | |
return round($value * 100, 0); | |
} | |
/** | |
* @param integer $value | |
* @return string | |
*/ | |
public static function convertToPresent($value) | |
{ | |
return \Yii::$app->formatter->asDecimal($value / 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment