Author Topic: Decimal format problem  (Read 1767 times)

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Decimal format problem
« on: 03/April/2010, 06:57:27 PM »
Where do I format the layout of the price?
I want to use the Dutch layout, being nnn,nn instead of the nBILL default setting nnn.nn
I've been looking into the code, but cannot find the place where to modify.
The file /administrator/components/com_nbill/framework/nbill.number.format.php seems to contain all kind of settings, but I don't understand it.

Please help in pointing me in the right direction how to solve this. I've downloaded 2.0.9 to have the latest version, but it did not make any difference: it will still only accept numerics with the '.' as decimal separator.

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,952
    • View Profile
Re: Decimal format problem
« Reply #1 on: 03/April/2010, 07:29:57 PM »
In /administrator/components/com_nbill/framework/nbill.number.format.php, where it says (on lines 38 to 41):

if (nbf_globals::$system_locale)
{
    @setlocale(LC_ALL, nbf_globals::$system_locale); //You could force this to a different locale here if your system default one is not right
}

...change it to:

/*if (nbf_globals::$system_locale)
{
    @setlocale(LC_ALL, nbf_globals::$system_locale); //You could force this to a different locale here if your system default one is not right
}*/
setlocale(LC_ALL, 'nl_NL', 'nl', 'NL', 'nl-NL', 'Dutch');

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Decimal format problem
« Reply #2 on: 05/April/2010, 11:09:14 AM »
Thanks for the fast response.

I tried your suggestion, but it does not solve the problem that I can only enter product-prices using the '.' as separator.
I'm creating a product using the backend/admin section of nBILL.
Are there page/field validations that need to be changed as well because they are hardcoded and not using the SETLOCAL switch?

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,952
    • View Profile
Re: Decimal format problem
« Reply #3 on: 05/April/2010, 02:25:20 PM »
You cannot use a comma as a decimal separator when entering prices in nBill. Only on the display of prices on invoices, reports, etc.

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Decimal format problem
« Reply #4 on: 06/April/2010, 08:10:44 AM »
Thanks for your answer.
I can live with the fact that prices have to be entered using the "." as separator, as long as they are shown correct.

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Decimal format problem
« Reply #5 on: 07/April/2010, 12:12:40 PM »
Now my problem with the iDEAL payment is solved, I looked a bit more in the format displaying.
Despite the change you recommended, I still see invoices and payment tables with the "." instead of the "," symbol, see the image.


Any other suggestions?

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,952
    • View Profile
Re: Decimal format problem
« Reply #6 on: 07/April/2010, 01:35:38 PM »
It depends on your server configuration and which locales are installed on your server (and what they are called). You might need to ask your hosting company whether the nl_NL locale is available or not. You could also try using a different locale that also uses a comma for a decimal separator, such as

setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge', 'deu_deu', 'deutsche', 'german');

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Decimal format problem
« Reply #7 on: 07/April/2010, 03:18:33 PM »
I'm sure you know better then I what the file nbill.number.format.php is supposed to do, but all of your suggestions don't work,  :'(
I run a small script (locale.php) to figure out what locales are available on the server and the nl_NL is present.

Digging a bit more into the file nbill.number.format.php, I do see however several places that do something with the separator, for instance line 50
$str_float = str_replace(",", ".", $float . ""); //Convert float to string, and if locale indicates a comma decimal separator, replace with dot

line 89
$ret_val = str_replace(",", "!!#!!", $ret_val); //In case decimal point becomes comma

line 107 you revert back to local en_US
@setlocale(LC_ALL, "en_US", "en-US", "en", "English_United States", "en_US.UTF-8");

And several places more, but I'm not a programmer (can make only small integration changes :-) ), so I'm a bit concerned that your suggestion has the right intend, but fails due to numerous 'hardcoded overwrites' in other places.

It would really be nice to show the HTML invoices as well as the frontend payments using the local settings.

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,952
    • View Profile
Re: Decimal format problem
« Reply #8 on: 07/April/2010, 04:17:37 PM »
For technical reasons, I have to process numbers using a dot as the separator, but the separator indicated by the locale is restored to the value returned by that function. The suggested code change definitely works on my server and on several others' servers, but it can sometimes be tricky to find exactly the right locale string. If you submit a support ticket giving me access to your site, I will see if I can get it working.

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Decimal format problem
« Reply #9 on: 08/April/2010, 08:45:30 AM »
I appriciate your support, but find it strange that I can't get it to work. I've been trying out several locale settings myself, using all kind of combinations but they don't make any difference.

What type of access do you need to look for yourself? FTP access and/or Joomla admin access?
I can surely give you temporary access to my test-site, I did that as well for fixing the problem with iDEAL. Access to the production site is not possible.

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,952
    • View Profile
Re: Decimal format problem
« Reply #10 on: 08/April/2010, 10:25:23 AM »
Joomla super admin access, and maybe FTP, depending on the file permissions.

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Decimal format problem
« Reply #11 on: 08/April/2010, 03:18:29 PM »
Hi Netshine,
I've created the Superadmin account, an email is sent to support@nbill.co.uk with the account information.
Let me know if you need more access.

Regards,
Sjaak

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,952
    • View Profile
Re: Decimal format problem
« Reply #12 on: 08/April/2010, 04:00:47 PM »
For some reason, the setlocale function always returns false on your system. That usually only happens if the locale you are trying to use is not installed. Anyway, as a workaround, I added the following code to the end of the function, just before the return statement:

    //Workaround for ineffective setlocale function
    if (!$suppress_commas && $format_negative) //Only applied to HTML output (invoices/reports)
    {
      $ret_val = str_replace(",", "!!#!!", $ret_val);
      $ret_val = str_replace(".", ",", $ret_val);
      $ret_val = str_replace("!!#!!", ".", $ret_val);
    }


...which has the same effect.

Offline svherpen

  • Full Member
  • ***
  • Posts: 27
    • View Profile
Re: Decimal format problem
« Reply #13 on: 09/April/2010, 01:26:27 PM »
Beautifull, I will implement this workaround also on the production server. Thanks for you help.

Offline wied

  • Jr. Member
  • **
  • Posts: 8
    • View Profile
Re: Decimal format problem
« Reply #14 on: 16/November/2010, 09:04:15 PM »
Hi,

You have to install the locales on your server or ask your ISP to do this or take another ISP.
Work fine for me!!!
 ;D