@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | * @throws Exception |
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | - public static function generaFormato($valor = 0, $options = []) |
|
| 43 | + public static function generaFormato($valor = 0, $options = [ ]) |
|
| 44 | 44 | { |
| 45 | 45 | |
| 46 | - $simbolo = isset($options['s']) ? $options['s'] : 'BsF'; |
|
| 47 | - $decimal = isset($options['d']) ? $options['d'] : 2; |
|
| 46 | + $simbolo = isset($options[ 's' ]) ? $options[ 's' ] : 'BsF'; |
|
| 47 | + $decimal = isset($options[ 'd' ]) ? $options[ 'd' ] : 2; |
|
| 48 | 48 | |
| 49 | 49 | if (!is_numeric($valor)) |
| 50 | 50 | throw new Exception("{$valor} debe indicar un número que sea válido"); |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | * @param array $options additional key/value attributes to include |
| 61 | 61 | * @return float |
| 62 | 62 | */ |
| 63 | - public static function quitarFormato($str, $options = []) |
|
| 63 | + public static function quitarFormato($str, $options = [ ]) |
|
| 64 | 64 | { |
| 65 | - $simbolo = isset($options['s']) ? $options['s'] : 'BsF'; |
|
| 66 | - $decimal = isset($options['d']) ? $options['d'] : 2; |
|
| 65 | + $simbolo = isset($options[ 's' ]) ? $options[ 's' ] : 'BsF'; |
|
| 66 | + $decimal = isset($options[ 'd' ]) ? $options[ 'd' ] : 2; |
|
| 67 | 67 | |
| 68 | 68 | return number_format(str_replace($simbolo, '', $str), $decimal, '.', ''); |
| 69 | 69 | } |
@@ -46,10 +46,12 @@ |
||
| 46 | 46 | $simbolo = isset($options['s']) ? $options['s'] : 'BsF'; |
| 47 | 47 | $decimal = isset($options['d']) ? $options['d'] : 2; |
| 48 | 48 | |
| 49 | - if (!is_numeric($valor)) |
|
| 50 | - throw new Exception("{$valor} debe indicar un número que sea válido"); |
|
| 51 | - if (!is_int($decimal)) |
|
| 52 | - throw new Exception("El valor {$decimal} no es válido"); |
|
| 49 | + if (!is_numeric($valor)) { |
|
| 50 | + throw new Exception("{$valor} debe indicar un número que sea válido"); |
|
| 51 | + } |
|
| 52 | + if (!is_int($decimal)) { |
|
| 53 | + throw new Exception("El valor {$decimal} no es válido"); |
|
| 54 | + } |
|
| 53 | 55 | |
| 54 | 56 | return $simbolo . ' ' . number_format($valor, $decimal, '.', ''); |
| 55 | 57 | } |