Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Decimal separator

Locked
esstein
Posts: 17
Joined: Tue Mar 08, 2011 12:45 am

Decimal separator

Unread post 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
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

Re: Decimal separator

Unread post by admin »

Evandro,

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

Steven
esstein
Posts: 17
Joined: Tue Mar 08, 2011 12:45 am

Re: Decimal separator

Unread post 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).
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

Re: Decimal separator

Unread post by admin »

.
Locked