[Bug] Formula number literals like 12.50, .5, 007 and 1E3 are treated as text
Before you submit this issue, have you checked the following
- Is this really a problem?
- I have searched the Github Issues for similar issues, but did not find anything.
Affected packages and versions
@univerjs/engine-formula 1.0.2 (also reproduced on dev at 618f9df2c)
Reproduction link
Number literals written in formula source are only treated as numbers when they are already in canonical JavaScript form. Literals such as 12.50, 0.10, .5, 007, -12.50 become text, and 1E3 / 1.5E+2 keep their source spelling when converted to text.
Minimal headless reproduction (Node.js, @univerjs/core + engine-formula + sheets + sheets-formula 1.0.2):
const ws = univerAPI.createWorkbook({}).getActiveSheet();
ws.getRange('A1').setFormula('=12.50');
ws.getRange('A2').setFormula('=0.10');
ws.getRange('A3').setFormula('=.5');
ws.getRange('A4').setValue(1);
ws.getRange('B1').setValue(0.75);
ws.getRange('T1').setFormula('=SUM(A1:A4)');
ws.getRange('T2').setFormula('=IF(B1>=0.50,"ok","low")');| Formula | Univer | Excel |
|---|---|---|
=12.50 |
"12.50" (text) |
12.5 |
=TYPE(12.50) |
2 |
1 |
=ISNUMBER(12.50) / =ISNUMBER(.5) |
FALSE |
TRUE |
=12.50=12.5 |
FALSE |
TRUE |
=12.50&"" |
"12.50" |
"12.5" |
=1E3&"" |
"1E3" |
"1000" |
=007&"" |
"007" |
"7" |
=ISNUMBER(INDEX({1.50,2},1)) |
FALSE |
TRUE |
=SUM(A1:A4) with A1:A3 = =12.50, =0.10, =.5 |
1 |
14.1 |
=IF(B1>=0.50,"ok","low") with B1 = 0.75 |
"low" |
"ok" |
Arithmetic such as =12.50*2 still works because the text is coerced back to a number. Comparisons, ISNUMBER, lookups, aggregation over the result cells, and text conversion are wrong.
This shows up often in generated spreadsheets: money and rate literals like 0.10, 12.50 and 0.50 are very common in formulas written by AI agents. I found it while evaluating Univer headlessly as the spreadsheet runtime for agent workflows.
Expected behavior
A number literal in formula source is always a number, regardless of trailing zeros, a leading dot, leading zeros or exponent notation, as in Excel.
Actual behavior
ValueNode.execute passes the raw token to ValueObjectFactory.create, which only returns a number when Number(rawValue).toString() === rawValue.trim(). That check is meant for cell text, where "000123456" must stay a string. For formula literals, it turns 12.50 into a string. Array constants go through ArrayValueObject._formatValue, which uses the same factory, so they have the same problem.
System information
Node.js 24.16.0, Windows 11
Source: dream-num/univer