Skip to content
This repository was archived by the owner on Oct 5, 2026. It is now read-only.
This repository was archived by the owner on Oct 5, 2026. It is now read-only.

BREAKING BUG: Calculation error, code treats '000 separator as decimal point #4

Closed

Description

@moontango

Image

To reproduce, create above as follows:

|       | Cost    | $1.16=1EUR | EUR     |
| ----- | ------- | ---------- | ------- |
|       | $1200   | 1.16       | MUL<EUR |
|       | $1500   | 1.16       | MUL<EUR |
| Total | SUM^USD |            | SUM^EUR |

What happens
The bottom right cell reads $EUR3.

What should happen:
The bottom right cell should result in EUR3132.

I am using the default "en" currency code. But it doesn't matter if I use de-DE etc.
The same error is made with DIV etc.- the code takes any source value and truncates any '000 separator as if it was a decimal point.

Activity

  1. moontango commented on Aug 27, 2025

    @moontango
    Author

    I've found the issue.

    In my settings, the max decimal place for fractions was set to 0. Basically the current code takes $1,200 and converts it to 1.2 as it looks to a decimal place to determine that "," is a '000 separator, and since it didn't find one, thinks that it is a decimal separator.

    The temporary fix is to set it to a positive integer, e.g. 1

    Code fix in the function extractNumber():

    extractNumber(str: string | null): number | null {
    ... 
    
        // --- Error code: This logic treats commas as decimal for US format like "1,200" ---
        //    
        // const commaIndex = numStr.lastIndexOf(',');
        // const dotIndex = numStr.lastIndexOf('.');
        // if (commaIndex > dotIndex) {
        //     numStr = numStr.replace(/\./g, '').replace(',', '.');
        // } else {
        //     numStr = numStr.replace(/,/g, '');
        // }
        //
        // --- Improved logic: Parses both US and European formats ---
    
        if (numStr.match(/^\d{1,3}(,\d{3})+(\.\d+)?$/)) {
            // US-style: "1,234.56" → "1234.56"
            numStr = numStr.replace(/,/g, '');
        } else if (numStr.match(/^\d{1,3}(\.\d{3})+(,\d+)?$/)) {
            // European-style: "1.234,56" → "1234.56"
            numStr = numStr.replace(/\./g, '').replace(',', '.');
        } else if (numStr.match(/^\d+(,\d+)?$/)) {
            // "1234,56" → "1234.56"
            numStr = numStr.replace(',', '.');
        }
        // --- End Improved Code ---
    
        const result = parseFloat(numStr);
        return !isNaN(result) ? result : null;
    
  2. added
    bug
    on Sep 19, 2025
  3. self-assigned this
    on Sep 19, 2025
  4. eatcodeplay commented on Sep 19, 2025

    @eatcodeplay
    Owner

    Hey @moontango, sorry for the late reply to this. Had health issues, but i'm back now. 💪
    I just released 0.2.4 which uses numeral.js instead for number extraction, as there were even more edge cases and it just became a hassle to cover them all 😆

    Let me know if that works for you now! 🤗

  5. moontango commented on Sep 23, 2025

    @moontango
    Author

    Just updated and set the decimal place to 0. Everything's working great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions