1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Not a Bug XenForo_Input::FLOAT does not take locale into account

Discussion in 'Resolved Bug Reports' started by Jon W, Aug 7, 2015.

  1. Jon W

    Jon W Well-Known Member

    In XenForo_Input, replacing:
                case self::FLOAT:
    $data floatval($data);
    with something more like:
                case self::FLOAT:
    $language XenForo_Visitor::getInstance()->getLanguage();
    $data str_replace($language['thousands_separator'], ""$data);
    $data str_replace($language["decimal_point"], "."$data);
    $data floatval($data);
    would allow users to enter decimals based on their selected locale.

    Similarly in XenForo_DataWriter for TYPE_FLOAT.
  2. Boothby

    Boothby Active Member

    I think it would confuse users. With the suggested code, 3.5 becomes 35 with German settings. A different number. ;) To solve this, the script must determine what the user input means. The script would have to to deal with a lot of variants of user input data. There is some example code on php.net.

    Let it be as is and keep it simple. :)
  3. Liam W

    Liam W Well-Known Member

    Well, if it's set to the german language (and the language creator set the language options correctly), then it would end up correct.

    It uses the users' selected language.

  4. Mike

    Mike XenForo Developer Staff Member

    The datawriter version should definitely not be changed. That reflects internal type changes.

    The input version can't really be changed either as this is a massive backwards compatibility break. Anywhere that uses the "standard" format of aaaa.bbb to represent a float would fail if "." represented a thousands operator. As an example, this is used for media cropping and tagging with values that are JS generated. I'm not positive whether browsers actually respect alternate formats in input[type=number].

    So if this is something you'd want to support, I think you'll need to do it manually. That said, there's a reason that we don't use floats if we can avoid it. :)
    Xon and Liam W like this.

Share This Page