decimal point is comma

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

decimal point is comma

Postby linux123 » Sun Oct 25, 2009 12:11 pm

Hi,

when displaying numbers in foreign languages, sometimes the decimal point must be shown as "," (comma), e.g. in Germany or the Netherlands.
Some time ago we figured out how to do this with xataface, converting the numbers with field__pullValue and field__pushValue for the forms and - additionally - with field__toString for displaying them elsewhere.

This now becomes rather tiresome, since a new project has dozens of number fields, so the functions for the conversions are just filling up the delegate class file with zillions of lines of redundant code.

Is there any way to handle this more automatically, e.g. is there some kind of standard xataface field method like "convert float field to HTML" and "convert HTML to float field", so that we can just create 2 or 3 functions and are done? I know this has been done with the "date" and "time" information, but I could not yet find the place where to put the code for l10n of decimal numbers.

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

Postby shannah » Mon Oct 26, 2009 3:03 pm

Can you do some research for me on this one? For starters can you recommend any open source PHP applications that provide an option to choose decimal point or comma. I'd like to see what the best practice is for this before proceeding with a general solution.

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

Applications

Postby linux123 » Tue Oct 27, 2009 8:47 am

Hi Steve,

on first thought, I can think of Joomla (a CMS) and xt:commerce or os:commerce (shopping carts) that can switch between locales quite easily. But these are rather complex systems.
If I select the language in the backend, everything from date/time to numbers or currency symols is automagically switched to the right locale setting.

AFAIK, under Linux, the layout of locales is configured with country/language specific files in /usr/lib/locale, so applications can read this information and format all input and output accordingly (depending on the locale currently in use). So this seems to be some kind of generic stuff - if you want to call it like this, it's a best practice, but maybe it's only valid for the LinuxOS.

If I find anything else on this I'll let you know.

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

Postby shannah » Tue Oct 27, 2009 9:46 am

OK.. i'll look into Joomla to see its strategy.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Jean » Wed Oct 28, 2009 1:51 am

Hello Steve and Bernd,
I found this that will format a string according to locale :
Code: Select all
function strtonumber( $str, $dec_point=null, $thousands_sep=null )
    {
        if( is_null($dec_point) || is_null($thousands_sep) ) {
            $locale = localeconv();
            if( is_null($dec_point) ) {
                $dec_point = $locale['decimal_point'];
            }
            if( is_null($thousands_sep) ) {
                $thousands_sep = $locale['thousands_sep'];
            }
        }
        $number = (float) str_replace($dec_point, '.', str_replace($thousands_sep, '', $str));
        if( $number == (int) $number ) {
            return (int) $number;
        } else {
            return $number;
        }
    }


Cheers
Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 16 guests

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