Skip to content

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

Open

Description

@jayhemnani9910

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions