Skip to content

Instantly share code, notes, and snippets.

@rmrevin
Last active January 30, 2016 17:02
Show Gist options
  • Save rmrevin/32bf0de1103a2dc673a6 to your computer and use it in GitHub Desktop.
Save rmrevin/32bf0de1103a2dc673a6 to your computer and use it in GitHub Desktop.
Money formatter helper
<?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