How to enter non US decimals into xataface?

12 views
Skip to first unread message

Richard Mücke

unread,
Nov 28, 2023, 12:18:06 AM11/28/23
to Xataface
Hi,

I want to enter decimals with "," as decimal delimiter:
1.25 in US would be 1,25 in DE

Using number_format in fields.ini shows the correct output (, instead of .).
But entering data always has to be with "." as delimiter (US-style).

I played with setlocale in index.php but nothing changes this.

How can I switch the input interpretation of decimals?

Thanks in advance.

Best regards
Richard


Richard Mücke

unread,
Nov 28, 2023, 7:02:37 AM11/28/23
to Xataface
Maybe I forund a solution. It would be nice, if you, Steve, or someone else could confirm my solution as the right way to do it. 
Thanks :)

The solution is to use the field__pushValue() and the fielt__pullValue() method:
http://xataface.com/wiki/field__pushValue

In the table class I added the following functions:
        function fieldname__pushValue($record, $el){
                $val = $el->getValue();
                $val = str_replace(",", ".", $val);
                $val = number_format(floatval($val), 2, ".", ",");
                if ( $val !== false ){
                        return $val;
                }
                return null;
            }
        function fieldname__pullValue($record, $el){
                $val = $record->val('fieldname');
                $val = number_format(floatval($val), 2, ",", ".");
                return $val;
        }


So I can enter "1,25" and get 1.25 in the database. Editing this field gets me the "1,25" again. Very nice.

Is this the right way to do it with xataface?

Thanks in advance.
Best regards
Richard
Reply all
Reply to author
Forward
0 new messages