Page 1 of 1

Decimal separator

PostPosted: Sun Jun 24, 2012 4:55 am
by esstein
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

Re: Decimal separator

PostPosted: Tue Aug 21, 2012 3:44 pm
by admin
Evandro,

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

Steven

Re: Decimal separator

PostPosted: Wed Aug 22, 2012 4:53 am
by esstein
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).

Re: Decimal separator

PostPosted: Wed Aug 22, 2012 1:56 pm
by admin
.