jspreadsheet / jspreadsheet/ce

Problems of negative sign

Open
#1,121 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
7.2k
Forks
890
PR merge metrics
No merged PRs in 30d

Description

When using "[-]#,##0" for the mask, the following problems occurred.

  1. The first few letters of an unsigned number are missing on loaded.
    10,000 --> 000
  2. SUM is not calculated correctly on edited.
    SUM(10,000, -10,000) --> 9,990

I solved it as follows in jExcel v3, so please consider.

jsuites.js line 5533

    } else if (pieces[index] == '[-]') {
        if (input == '-' || input == '+') {
            values[index] = input;
        } else if (input.match(/[0-9]/g)) {
            pieces.splice(index, 1);
            values[index] = input;
            return true;
        } else {
            values[index] = ' ';
        }
        index++;
        return true;

jexcel.js line 11611

    } else if (typeof elt === 'string') {

        var parseFormatedNumber = function (str) {
            var t = (1111).toLocaleString().replace(/1/g, '');
            var d = (1.1).toLocaleString().replace(/1/g, '');
            return parseFloat(
                str.replace(new RegExp('\\' + t, 'g'), '')
                .replace(new  RegExp('\\' + d), '.')
            );
        };
        elt = parseFormatedNumber(elt);

        var parsed = parseFloat(elt);
        !isNaN(parsed) && (result += parsed);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two negative-sign cases described in the issue, then inspect jsuites.js around line 5533 and jexcel.js around line 11611. Verify the behavior for the "[-]#,##0" mask and the SUM example; done means 10,000 is preserved when loaded and SUM(10,000, -10,000) produces the correct result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.