You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: in-built function SUBSTITUTE does not work as expected #1289
I am looking for a way to convert values that end in decimal point to number. For example I would like "13." to be converted to 13
issue 1.
in excel NUMBERVALUE function does the job. NUMBERVALUE("13.") results in 13
But I did not see it as one of the supported built-in functions. So I thought perhaps i could use SUBSTITUTE, and then run into this bug
issue 2.
import { HyperFormula } from 'hyperformula';
describe('hyperformula', () => {
it('does not substitute correctly', () => {
const hfInstance = HyperFormula.buildFromArray([], {
licenseKey: 'gpl-v3',
});
const goodFormula = '=SUBSTITUTE("13x", "x", "x00")';
const result1 = hfInstance.calculateFormula(goodFormula, 0);
expect(result1).toStrictEqual('13x00');
// in the formula below I was expecting it to behave
// just like the one above, but it doesn't.
// it returns ".00.00.00"
const badFormula = '=SUBSTITUTE("13.", ".", ".00")';
const result2 = hfInstance.calculateFormula(badFormula, 0);
expect(result2).toStrictEqual('13.00');
});
});
@adrianszymanski89 Our implementation of SUBSTITUTE uses RegExp to search for text patterns. That is what causes this weird result.
This behavior is neither compliant with the standard nor consistent with other popular software, so must be considered a bug. We will work on it according to our priorities.
@makarandp0 As a workaround you may escape the special regexp symbols in the search pattern with double backslash (\\)
Activity
adrianszymanski89 commentedon Jun 28, 2023
Hi @makarandp0
Thank you for reporting this. I was able to recreate the issue on my side: https://jsfiddle.net/handsoncode/m1u7rnok/
This function indeed works for every other sign than
..@sequba Can you please take a look at this?
sequba commentedon Jun 29, 2023
@adrianszymanski89 Our implementation of
SUBSTITUTEuses RegExp to search for text patterns. That is what causes this weird result.This behavior is neither compliant with the standard nor consistent with other popular software, so must be considered a bug. We will work on it according to our priorities.
@makarandp0 As a workaround you may escape the special regexp symbols in the search pattern with double backslash (
\\)AMBudnik commentedon Dec 27, 2023
Hi @makarandp0
Thank you for reporting the issue! I have good news. We just fixed it and released it under HyperFormula v 2.6.1.
You can read mire about the changes for this version at https://github.com/handsontable/hyperformula/releases/tag/2.6.1