Git Product home page Git Product logo

Comments (1)

wzlzking avatar wzlzking commented on June 2, 2024

I have resolved this issue and should add the following code to the write() method in SPSS\Sav\Record\ValueLabel.php

//fix Convert non numeric values to double type
if (!$convertToDouble && !is_numeric($item['value'])) {
$item['value'] = Utils::stringToDouble($item['value']);
}

public function write(Buffer $buffer)
    {
        $var = (count($this->variables) > 0) ? $this->variables[count($this->variables) - 1] : null;
        $convertToDouble = (isset($var) && ($var->width > 0));

        // Value label record.
        $buffer->writeInt(self::TYPE);
        $buffer->writeInt(\count($this->labels));
        foreach ($this->labels as $item) {
            $labelLength = min(mb_strlen($item['label']), self::LABEL_MAX_LENGTH);
            $label = mb_substr($item['label'], 0, $labelLength);
            $labelLengthBytes = mb_strlen($label, '8bit');
            while ($labelLengthBytes > 255) {
                // Strip one char, can be multiple bytes
                $label = mb_substr($label, 0, -1);
                $labelLengthBytes = mb_strlen($label, '8bit');
            }

            if ($convertToDouble) {
                $item['value'] = Utils::stringToDouble($item['value']);
            }

            //fix Convert non numeric values to double type
            if (!$convertToDouble && !is_numeric($item['value'])) {
                $item['value'] = Utils::stringToDouble($item['value']);
            }

            $buffer->writeDouble($item['value']);
            $buffer->write(\chr($labelLengthBytes));
            $buffer->writeString($label, Utils::roundUp($labelLengthBytes + 1, 8) - 1);
        }

        // Value label variable record.
        $buffer->writeInt(4);
        $buffer->writeInt(\count($this->indexes));
        foreach ($this->indexes as $varIndex) {
            $buffer->writeInt($varIndex);
        }
    }
`

from spss.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.