number format with decimal point

A place for users and developers of the Xataface to discuss and receive support.

number format with decimal point

Postby linux123 » Sun Aug 02, 2009 4:57 am

Hi,

my current import filters for the products database are reading German style decimal numbers and date formats from an XML or CSV.
I found that while the date is automatically formatted from "dd.mm.yy" to the MySQL format, my decimal numbers are cut off because the "," is not automatically converted to ".".

While it is very easy to convert this before importing the actual number, I wonder whether this should be handled automatically by some kind of locale setting. The date is automatically converted - who does it, Xataface or MySQL? Maybe the numbers conversion should be at the same place?

My users are also complaining that they have to enter "." instead of "," for numbers when using xataface forms. I know this can be changed by some type of field filters, but I'm not sure if this would be a clean solution to the general problem?

Bernd
linux123
 
Posts: 25
Joined: Tue Feb 10, 2009 1:00 pm

Postby shannah » Wed Aug 05, 2009 12:50 pm

I haven't had to deal with this much but I suspect the solution might be in the php setlocale() function. With the LC_NUMERIC setting.

http://ca.php.net/setlocale

Call this at the beginning of your index.php file and see what happens.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby linux123 » Thu Aug 06, 2009 6:45 am

Unfortunately, setlocale (LC_NUMERIC, 'de_DE'); or $loc_de = setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); don't seem to have any effect on Xataface.

So maybe something inside Xataface accidentally resets the default locale to C or en_US?

To be honest, I expected
[languages]
de="Deutsch"
to do the dirty work or the browser to somehow know the locale from the environment. The latter would make the most sense, since it could well be that on a xataface application, one guy is sitting in the UK and the other in Germany, both accessing the same database via the Internet. Of course the UK guy gets the UK locale and the German guy the DE locale for work, and this should work for the same application.

Bernd
linux123
 
Posts: 25
Joined: Tue Feb 10, 2009 1:00 pm

Postby linux123 » Thu Aug 06, 2009 7:02 am

I was not 100% correct on the previous message.
After some more testing, I found that the locale setting does affect xataface, but now neither "5.95" nor "5,95" will work - the digits beyond the comma will always be cut off.
linux123
 
Posts: 25
Joined: Tue Feb 10, 2009 1:00 pm

Postby shannah » Thu Aug 06, 2009 7:41 am

OK. I suspect that the numbers are probably getting cut off in MySQL - as mysql has no way of using commas as decimal points natively.

I suspect that is may be as simple as adjusting the serialization function to convert float numbers back to a decimal for storage in MySQL.

Give this a shot. In Dataface/Serializer.php, find the part where it has
Code: Select all
if ( $table->isFloat( $fieldname) ){
         return doubleval($value);
      }


Change it to
Code: Select all
if ( $table->isFloat( $fieldname) ){
   return vsprintf('%F',$value);
}


And keep your call to setlocale(LC_NUMERIC, ....

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby linux123 » Thu Aug 06, 2009 8:16 am

Hi Steve,
thanks for the patch.
Now I can enter '5.95' again, but not '5,95'...
Maybe I'm still doing something wrong with the locale, I'll check that out tonight, my PHP is not very good I'm afraid (I used to do everything in Perl, but there is no xataface for Perl ...)
BTW, the numeric values in the list or forms are also displayed as "0.00".
Bernd
linux123
 
Posts: 25
Joined: Tue Feb 10, 2009 1:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 38 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved