[Bug]: INT() truncates negative numbers instead of rounding them down

Aperta Adatta ai principianti
#1,881 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend, data

Direzione di ricerca

Inizia da RoundingPlugin.intFunc, indicato nell’issue, ed esamina i test vicini sul comportamento di arrotondamento di INT. Controlla i casi =INT(-2.5), =INT(-8.9) e =INT(-0.1) insieme a valori positivi e numeri interi. Il risultato atteso è che gli input negativi vengano arrotondati per difetto agli interi previsti, mentre il comportamento esistente per i valori positivi e i numeri interi rimanga corretto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

INT rounds negative numbers toward zero:

Formula HyperFormula 3.5.0 Excel / Google Sheets / LibreOffice
=INT(-2.5) -2 -3
=INT(-8.9) -8 -9
=INT(-0.1) 0 -1

Excel's documentation uses =INT(-8.9) = -9 as its example ("Rounds a number down to the nearest integer"), and OpenFormula defines INT the same way. Positive numbers and integers are fine.

RoundingPlugin.intFunc (develop 5a6eb09) returns -Math.floor(-x) for negative input, which is truncation; Math.floor(x) gives the expected result for both signs.

Any sheet that splits a negative amount with INT (whole units vs remainder, e.g. A1-INT(A1)) gets a different result than it does in Excel.

Video or screenshots

No response

Demo
const hf = HyperFormula.buildFromArray([['=INT(-2.5)']], { licenseKey: 'gpl-v3' })
hf.getCellValue({ sheet: 0, row: 0, col: 0 }) // -2, expected -3
HyperFormula version

3.5.0

Your framework

None (plain Node.js)

Your environment

Node.js 24, Linux x64

Lingua principale
TypeScript
Stelle
2.8k
Fork
175
Merge medio
2g 8h
PR unite (30g)
21

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di handsontable/hyperformula

Tutte le issue di handsontable/hyperformula

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.