Forum Discussion

EternalVoid's avatar
EternalVoid
Copper Contributor
Feb 05, 2025
Solved

REPT function not working correctly for values 1 and 2

Hi all, Either I found a bug in a way REPT function work, or I really do not understand something. I'll explain step by step how to reproduce the problem. In A1 we put 0, A2 put 0.1, in A3 0.2 and...
  • m_tarler's avatar
    Feb 05, 2025

    I'm 99% sure this is due to round off errors in Excel.  Excel does have a limited resolution of bits to represent a number and although 0.8 and 0.9 are only 1 decimal place to you and me, a computer is based on base 2 and therefor I suspect the closest representation is ever so slightly less than 0.8 and 0.9 and that REPT is designed to use some form of INT() of the number.  IF you add a ROUND or MROUND into the equation it will work fine.

    Intrestingly #1 - You can also use INT() of the value as shown in the image below, where I use =REPT("1",INT((1-A2:A12)*10)) and it works 'correctly 

    Interstingly #2 - if you set up the initial column using =SEQUENCE(11, , 0, 0.1) it also behaves 'correctly'.

    If you want to learn more about EXCEL rounding errors there are a number of excellent discussion given in this forum.

     

Resources