PHP Classes

File: extenso.php

Recommend this page to a friend!
  Classes of Pablo DallOglio   extenso   extenso.php   Download  
File: extenso.php
Role: ???
Content type: text/plain
Description: class file
Class: extenso
Author: By
Last change:
Date: 23 years ago
Size: 2,765 bytes
 

Contents

Class file image Download
<? // Essa classe tem como meta retornar um número por extenso no idioma português // Autor : Pablo Dall'Oglio (pablo@univates.br) // Date : Wednesday, 16, 2001 class extenso { // função que retorna os números por extenso de 3 em 3 function trio_extenso($cVALOR) { $aUNID = array(""," UM "," DOIS "," TRES "," QUATRO "," CINCO "," SEIS "," SETE "," OITO "," NOVE "); $aDEZE = array(""," "," VINTE E"," TRINTA E"," QUARENTA E"," CINQUENTA E"," SESSENTA E"," SETENTA E"," OITENTA E"," NOVENTA E "); $aCENT = array("","CENTO E","DUZENTOS E","TREZENTOS E","QUATROCENTOS E","QUINHENTOS E","SEISCENTOS E","SETECENTOS E","OITOCENTOS E","NOVECENTOS E"); $aEXC = array(" DEZ "," ONZE "," DOZE "," TREZE "," QUATORZE "," QUINZE "," DESESSEIS "," DESESSETE "," DEZOITO "," DESENOVE "); $nPOS1 = substr($cVALOR,0,1); $nPOS2 = substr($cVALOR,1,1); $nPOS3 = substr($cVALOR,2,1); $cCENTE = $aCENT[($nPOS1)]; $cDEZE = $aDEZE[($nPOS2)]; $cUNID = $aUNID[($nPOS3)]; if (substr($cVALOR,0,3) == "100") { $cCENTE = "CEM "; } if (substr($cVALOR,1,1) == "1") { $cDEZE = $aEXC[$nPOS3]; $cUNID = ""; } $cRESULT = $cCENTE . $cDEZE . $cUNID; $cRESULT = substr($cRESULT,0,strlen($cRESULT)-1); return $cRESULT; } // principal função da classe responsável pelo retorno do número por extenso function porextenso($cVALOR, $lMOEDA) { //pict 999.999.999,99 $zeros = "000.000.000,00"; $cVALOR = number_format($cVALOR,2); $cVALOR = substr($zeros,0,strlen($zeros)-strlen($cVALOR)) . $cVALOR; if ($lMOEDA) { $cMOEDA_SINGULAR = " REAL"; $cMOEDA_PLURAL = " REAIS"; } else { $cMOEDA_SINGULAR = ""; $cMOEDA_PLURAL = ""; } //cVALOR = transform( nVALOR, "@ZE 999,999,999.99"); //$cRETURN = substr($cVALOR,0,3) . substr($cVALOR,4,3) . substr($cVALOR,8,3); $cMILHAO = $this->trio_extenso(substr($cVALOR,0,3)) . ( (substr($cVALOR,0,3)>1) ? ' MILHOES' : '' ); $cMILHAR = $this->trio_extenso(substr($cVALOR,4,3)) . ( (substr($cVALOR,4,3)>0) ? ' MIL' : '' ); $cUNIDAD = $this->trio_extenso(substr($cVALOR,8,3)) . ( ($nVALOR==1) ? $cMOEDA_SINGULAR : $cMOEDA_PLURAL); $cCENTAV = $this->trio_extenso("0" . substr($cVALOR,12,2)) . ((substr($cVALOR,12,2)>0) ? " CENTAVOS" : ""); $cRETURN = $cMILHAO . ((strlen(trim($cMILHAO))<>0 && strlen(trim($cMILHAR))<>0) ? ", " : "") . $cMILHAR . ((strlen(trim($cMILHAR))<>0 && strlen(trim($cUNIDAD))<>0) ? ", " : "") . $cUNIDAD . ((strlen(trim($cUNIDAD))<>0 && strlen(trim($cCENTAV))<>0) ? ", " : "") . $cCENTAV; return $cRETURN; } } ?>