Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-279197

Some commands have inconsistent results for rounding negative numbers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.21.4, 25w02a
    • Community Consensus
    • Commands

      The bug

      Some commands, such as /data get, will round decimals down as their result. Other commands, such as /attribute ... get, will truncate decimals to a whole number, resulting in an inconsistency for handling negative numbers.

      Affected commands

      Commands that truncate decimals:

      • /attribute ... get ...
      • /execute store ... (byte|short|int|long) <decimal_scale>
      • /worldborder add <distance>

      Commands that round decimals down:

      • /data get ...

      The results for inserting decimals into integer arrays are also inconsistent, which has been reported in MC-276879, so I will skip them.

      Ways to reproduce

      To reproduce, you can either:

      • Install the attached data pack, and run /function mc-279197:test to see whether -7.3 is rounded to -7 or -8
      • Follow the steps below to test the specific cases between /data and /attribute

      Steps to reproduce

      1. Summon a cow with a maximum health of 7.3
        /summon cow ~ ~ ~ {attributes: [{id: "minecraft:max_health", base: 7.3d}]}
      2. Create a scoreboard
        /scoreboard objectives add MC-279197 dummy
        /scoreboard objectives setdisplay sidebar MC-279197
      3. Attempt to store the maximum health via /data and /attribute
        /execute store result score data_get MC-279197 run data get entity @n[type=cow] attributes[{id: "minecraft:max_health"}].base -1
        /execute store result score attribute_get MC-279197 run attribute @n[type=cow] minecraft:max_health get -1
      4. Take note as to whether these two commands have consistent behavior for rounding negative numbers.

      Observed results

      /data rounds the result down to -8, while /attribute truncates the result to -7.

      Expected results

      The results of /data and /attribute should be the same, both being -7 or -8.

            Unassigned Unassigned
            cxc81 cxc81
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              CHK: