Search code examples
htmlperlnumbersdecimaltruncate

How to truncate a number


I should display numbers to a table. But I need The number has only two characters after a comma. How to do it correctly.

            $score =  $schet;
%>
            <tr class="ten" >
                <td class="six" > <%= $schet %></td>
                <td> <%= $d->start %></td>
                <td> <%= $d->end   %></td>
            </tr>
<%
        }

Solution

  • Use sprintf:

    my $number_with_two_decimal_places = sprintf '%.2f', $float;