delucaspinto

[PHP] Ajuste valor php / laravel

Jun 12th, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. // Database em float
  2.  
  3. // para converter no controller
  4. function strReplace($variable){
  5.     if(strlen($variable) >= 7){
  6.         $b = str_replace('.','',$variable);
  7.         $a = str_replace(',','.',$b);
  8.     }else{
  9.         $a = str_replace(',','.',$variable);
  10.     }
  11.     return $a;
  12. }
  13.  
  14. $valor_passado = Input::get('valor'); //R$ 123,45
  15. $vlr = str_replace('R$ ','', $valor_passado);
  16. $valor = strReplace($vlr);
  17.  
  18.  
  19. // para formatar no html/php
  20. {{ number_format($valor, 2, ',', ' ') }}
Advertisement
Add Comment
Please, Sign In to add comment