1. next bigger interger

    August 12, 2008 by pierre

    I’m working on PDF templates using FPDF, the templates are based on a grid and I had to find how much of the grid’s units different images are using, e.g. if an image width is 1.3 units I need to make 2 units space for it in the the grid.

    In other words I needed to “round” a floating point number, but always to a bigger number so the round php function would not be usefull :

    echo round(1.2); // 1
    echo round(1.6); // 2

    Then I thought that what I wanted was the “next bigger integer”, and it felt in place : change the float to an integer and add one.

    echo ((int) 1.2) + 1; // 2
    echo ((int) 1.6) + 1; // 2

    This is super simple but it seem to me a good exemple of how formulating what you want to do in english can help when programming.