Skip to content

Possibly bug - FLOOR and FLOOR.MATH  #407

Closed
@ArtemBro

Description

@ArtemBro

Sorry I don't use PhpSpreadsheet, but I found this bug in PHPExcel 1.8.1 and maybe it's in PhpSpreadsheet too.

I have .ods file which contains cell with formula FLOOR.MATH
But when I read this file and try to save to .xls I got exception:

Formula Error: Wrong number of arguments for FLOOR() function: 3 given, 2 expected

I found that:
FLOOR has 2 parameters https://support.office.com/en-us/article/floor-function-14bb497c-24f2-4e04-b327-b0b4de5a8886

FLOOR.MATH has 3 parameters https://support.office.com/en-us/article/floor-math-function-c302b599-fbdb-4177-ba19-2c2b1249a2f5

Perhaps there is a bug, and the FLOOR.MATH (with 3 parameters) is recognized as FLOOR (with 2 parameters)

Activity

stale

stale commented on May 5, 2018

@stale

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

oleibman

oleibman commented on May 10, 2025

@oleibman
Collaborator

Ugh. Reluctantly reopening issue.

Per https://wiki.documentfoundation.org/Documentation/Calc_Functions/FLOOR:

  • When Calc saves a spreadsheet to Excel 2007-365 (*.xlsx) format, any call to Calc's FLOOR function is converted to a call to Excel's FLOOR.MATH function, and any call to Calc's FLOOR.XCL function is converted to a call to Excel's FLOOR function.
  • When Calc opens a spreadsheet in Excel 2007-365 (*.xlsx) format, any call to Excel's FLOOR function is converted to a call to Calc's FLOOR.XCL function.

Likewise, per https://wiki.documentfoundation.org/Documentation/Calc_Functions/CEILING:

  • When Calc saves a spreadsheet to Excel 2007-365 (*.xlsx) format, any call to Calc's CEILING function is converted to a call to Excel's CEILING.MATH function, and any call to Calc's CEILING.XCL function is converted to a call to Excel's CEILING function.
  • When Calc opens a spreadsheet in Excel 2007-365 (*.xlsx) format, any call to Excel's CEILING function is converted to a call to Calc's CEILING.XCL function.

In other words, using FLOOR or CEILING is a trap if you intend to use OpenOffice/LibreOffice. You should strive to use FLOOR.MATH or FLOOR.PRECISE, whichever is most suitable; likewise for CEILING. And it seems like the MATH and PRECISE functions needs some special flourishes on write as well. Sigh. If I can figure out a way to document this better, or fix it, I will do so.

added a commit that references this issue on May 11, 2025
39511e0
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

      Participants

      @oleibman@ArtemBro

      Issue actions

        Possibly bug - FLOOR and FLOOR.MATH · Issue #407 · PHPOffice/PhpSpreadsheet