Decimal separator

Decimal separator

Postby esstein » Sun Jun 24, 2012 4:55 am

Hi,

I have made a small modification on reformatField function, file "productionnu2/common.php", to accepts any kind of decimal and separator numeric formats.

The idea is remove thousands "separator", based on textFormatsArray->separator, and replace the "textFormatsArray->decimal" to standard dot ("."). It is simple a can be used on any kind of number formats.

On:
Code: Select all
function reformatField($pValue, $pFormat,$addSingleQuotes = true){
// reformats value ready for insertion into database table
//originally formatted via rules in textFormatsArray()
...


Replace the original code:
Code: Select all
    if (in_array($pFormat, array('14','15','16','17','18','19'))){ //---number with commas
      return $sq . str_replace(',', '', $pValue) . $sq;
    }


... to:
Code: Select all
    if (in_array($pFormat, array('14','15','16','17','18','19'))){ //---number with commas
      return $sq . str_replace($FORMAT[$pFormat]->decimal, '.', str_replace($FORMAT[$pFormat]->separator, '', $pValue)) . $sq;
    }



Now, you can use your money regional settings on nuBuilder, like we have in Brazil:
Code: Select all
function textFormatsArray(){

//-----number formats
...
   $format[16]->type        = 'number';
   $format[16]->format      = '2';
   $format[16]->decimal     = ',';
   $format[16]->separator   = '.';
   $format[16]->sample      = '10.000,00';
   $format[16]->phpdate     = '';
   $format[16]->sql         = 'FORMAT(??,2)';


Maybe it helps someone or it can be added on official builds.

Evandro
esstein
 
Posts: 17
Joined: Tue Mar 08, 2011 9:15 am

Re: Decimal separator

Postby admin » Tue Aug 21, 2012 3:44 pm

Evandro,

Euro currency formats have been added in version 2.7.4.4 (out in the next day or so)

Steven
admin
Site Admin
 
Posts: 3079
Joined: Mon Jun 15, 2009 9:53 am

Re: Decimal separator

Postby esstein » Wed Aug 22, 2012 4:53 am

Very good, thanks.

My workaround still working for country's that use space (' ') to separate numbers, because when I use str_replace($FORMAT[$pFormat]->separator, '', $pValue), it will replace anyone character configured on $format[16]->separator (hard-coded on common.php).
esstein
 
Posts: 17
Joined: Tue Mar 08, 2011 9:15 am

Re: Decimal separator

Postby admin » Wed Aug 22, 2012 1:56 pm

.
admin
Site Admin
 
Posts: 3079
Joined: Mon Jun 15, 2009 9:53 am


Return to Project Contributions



cron